2010-05-11 19:42:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-05-11 21:36:01 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
2010-11-16 22:09:02 +00:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// <fstream>
|
|
|
|
|
|
|
|
// template <class charT, class traits = char_traits<charT> >
|
|
|
|
// class basic_fstream
|
|
|
|
|
|
|
|
// void swap(basic_fstream& rhs);
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <cassert>
|
2013-03-22 20:05:40 +00:00
|
|
|
#include "platform_support.h"
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2013-03-22 20:05:40 +00:00
|
|
|
std::string temp1 = get_temp_file_name();
|
|
|
|
std::string temp2 = get_temp_file_name();
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2013-03-22 20:05:40 +00:00
|
|
|
std::fstream fs1(temp1.c_str(), std::ios_base::in | std::ios_base::out
|
2011-07-18 23:51:21 +00:00
|
|
|
| std::ios_base::trunc);
|
2013-03-22 20:05:40 +00:00
|
|
|
std::fstream fs2(temp2.c_str(), std::ios_base::in | std::ios_base::out
|
2011-07-18 23:51:21 +00:00
|
|
|
| std::ios_base::trunc);
|
2010-05-11 19:42:16 +00:00
|
|
|
fs1 << 1 << ' ' << 2;
|
|
|
|
fs2 << 2 << ' ' << 1;
|
|
|
|
fs1.seekg(0);
|
|
|
|
fs1.swap(fs2);
|
|
|
|
fs1.seekg(0);
|
|
|
|
int i;
|
|
|
|
fs1 >> i;
|
|
|
|
assert(i == 2);
|
|
|
|
fs1 >> i;
|
|
|
|
assert(i == 1);
|
|
|
|
i = 0;
|
|
|
|
fs2 >> i;
|
|
|
|
assert(i == 1);
|
|
|
|
fs2 >> i;
|
|
|
|
assert(i == 2);
|
|
|
|
}
|
2013-03-22 20:05:40 +00:00
|
|
|
std::remove(temp1.c_str());
|
|
|
|
std::remove(temp2.c_str());
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2013-03-22 20:05:40 +00:00
|
|
|
std::wfstream fs1(temp1.c_str(), std::ios_base::in | std::ios_base::out
|
2011-07-18 23:51:21 +00:00
|
|
|
| std::ios_base::trunc);
|
2013-03-22 20:05:40 +00:00
|
|
|
std::wfstream fs2(temp2.c_str(), std::ios_base::in | std::ios_base::out
|
2011-07-18 23:51:21 +00:00
|
|
|
| std::ios_base::trunc);
|
2010-05-11 19:42:16 +00:00
|
|
|
fs1 << 1 << ' ' << 2;
|
|
|
|
fs2 << 2 << ' ' << 1;
|
|
|
|
fs1.seekg(0);
|
|
|
|
fs1.swap(fs2);
|
|
|
|
fs1.seekg(0);
|
|
|
|
int i;
|
|
|
|
fs1 >> i;
|
|
|
|
assert(i == 2);
|
|
|
|
fs1 >> i;
|
|
|
|
assert(i == 1);
|
|
|
|
i = 0;
|
|
|
|
fs2 >> i;
|
|
|
|
assert(i == 1);
|
|
|
|
fs2 >> i;
|
|
|
|
assert(i == 2);
|
|
|
|
}
|
2013-03-22 20:05:40 +00:00
|
|
|
std::remove(temp1.c_str());
|
|
|
|
std::remove(temp2.c_str());
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|