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 // <sstream>
11
12 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
13 // class basic_stringstream
14
15 // template <class charT, class traits, class Allocator>
16 // void
17 // swap(basic_stringstream<charT, traits, Allocator>& x,
18 // basic_stringstream<charT, traits, Allocator>& y);
19
20 #include <sstream>
21 #include <cassert>
22
main()23 int main()
24 {
25 {
26 std::stringstream ss0(" 123 456 ");
27 std::stringstream ss;
28 swap(ss, ss0);
29 assert(ss.rdbuf() != 0);
30 assert(ss.good());
31 assert(ss.str() == " 123 456 ");
32 int i = 0;
33 ss >> i;
34 assert(i == 123);
35 ss >> i;
36 assert(i == 456);
37 ss << i << ' ' << 123;
38 assert(ss.str() == "456 1236 ");
39 ss0 << i << ' ' << 123;
40 assert(ss0.str() == "456 123");
41 }
42 {
43 std::wstringstream ss0(L" 123 456 ");
44 std::wstringstream ss;
45 swap(ss, ss0);
46 assert(ss.rdbuf() != 0);
47 assert(ss.good());
48 assert(ss.str() == L" 123 456 ");
49 int i = 0;
50 ss >> i;
51 assert(i == 123);
52 ss >> i;
53 assert(i == 456);
54 ss << i << ' ' << 123;
55 assert(ss.str() == L"456 1236 ");
56 ss0 << i << ' ' << 123;
57 assert(ss0.str() == L"456 123");
58 }
59 }
60