1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <fstream>
11
12 // template <class charT, class traits = char_traits<charT> >
13 // class basic_fstream
14
15 // template <class charT, class traits>
16 // void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y);
17
18 #include <fstream>
19 #include <cassert>
20
main()21 int main()
22 {
23 char temp1[L_tmpnam], temp2[L_tmpnam];
24 tmpnam(temp1);
25 tmpnam(temp2);
26 {
27 std::fstream fs1(temp1, std::ios_base::in | std::ios_base::out
28 | std::ios_base::trunc);
29 std::fstream fs2(temp2, std::ios_base::in | std::ios_base::out
30 | std::ios_base::trunc);
31 fs1 << 1 << ' ' << 2;
32 fs2 << 2 << ' ' << 1;
33 fs1.seekg(0);
34 swap(fs1, fs2);
35 fs1.seekg(0);
36 int i;
37 fs1 >> i;
38 assert(i == 2);
39 fs1 >> i;
40 assert(i == 1);
41 i = 0;
42 fs2 >> i;
43 assert(i == 1);
44 fs2 >> i;
45 assert(i == 2);
46 }
47 std::remove(temp1);
48 std::remove(temp2);
49 {
50 std::wfstream fs1(temp1, std::ios_base::in | std::ios_base::out
51 | std::ios_base::trunc);
52 std::wfstream fs2(temp2, std::ios_base::in | std::ios_base::out
53 | std::ios_base::trunc);
54 fs1 << 1 << ' ' << 2;
55 fs2 << 2 << ' ' << 1;
56 fs1.seekg(0);
57 swap(fs1, fs2);
58 fs1.seekg(0);
59 int i;
60 fs1 >> i;
61 assert(i == 2);
62 fs1 >> i;
63 assert(i == 1);
64 i = 0;
65 fs2 >> i;
66 assert(i == 1);
67 fs2 >> i;
68 assert(i == 2);
69 }
70 std::remove(temp1);
71 std::remove(temp2);
72 }
73