member_swap.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===// 2// 3// ��������������������The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <fstream> 11 12// template <class charT, class traits = char_traits<charT> > 13// class basic_ofstream 14 15// void swap(basic_ofstream& rhs); 16 17#include <fstream> 18#include <cassert> 19 20int main() 21{ 22 { 23 std::ofstream fs1("test1.dat"); 24 std::ofstream fs2("test2.dat"); 25 fs1 << 3.25; 26 fs2 << 4.5; 27 fs1.swap(fs2); 28 fs1 << ' ' << 3.25; 29 fs2 << ' ' << 4.5; 30 } 31 { 32 std::ifstream fs("test1.dat"); 33 double x = 0; 34 fs >> x; 35 assert(x == 3.25); 36 fs >> x; 37 assert(x == 4.5); 38 } 39 remove("test1.dat"); 40 { 41 std::ifstream fs("test2.dat"); 42 double x = 0; 43 fs >> x; 44 assert(x == 4.5); 45 fs >> x; 46 assert(x == 3.25); 47 } 48 remove("test2.dat"); 49 { 50 std::wofstream fs1("test1.dat"); 51 std::wofstream fs2("test2.dat"); 52 fs1 << 3.25; 53 fs2 << 4.5; 54 fs1.swap(fs2); 55 fs1 << ' ' << 3.25; 56 fs2 << ' ' << 4.5; 57 } 58 { 59 std::wifstream fs("test1.dat"); 60 double x = 0; 61 fs >> x; 62 assert(x == 3.25); 63 fs >> x; 64 assert(x == 4.5); 65 } 66 remove("test1.dat"); 67 { 68 std::wifstream fs("test2.dat"); 69 double x = 0; 70 fs >> x; 71 assert(x == 4.5); 72 fs >> x; 73 assert(x == 3.25); 74 } 75 remove("test2.dat"); 76} 77