1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <sstream>
10 
11 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12 // class basic_stringstream
13 
14 // void str(const basic_string<charT,traits,Allocator>& str);
15 
16 #include <sstream>
17 #include <cassert>
18 
19 int main()
20 {
21     {
22         std::stringstream ss(" 123 456 ");
23         assert(ss.rdbuf() != 0);
24         assert(ss.good());
25         assert(ss.str() == " 123 456 ");
26         int i = 0;
27         ss >> i;
28         assert(i == 123);
29         ss >> i;
30         assert(i == 456);
31         ss << i << ' ' << 123;
32         assert(ss.str() == "456 1236 ");
33         ss.str("5466 89 ");
34         ss >> i;
35         assert(i == 5466);
36         ss >> i;
37         assert(i == 89);
38         ss << i << ' ' << 321;
39         assert(ss.str() == "89 3219 ");
40     }
41     {
42         std::wstringstream ss(L" 123 456 ");
43         assert(ss.rdbuf() != 0);
44         assert(ss.good());
45         assert(ss.str() == L" 123 456 ");
46         int i = 0;
47         ss >> i;
48         assert(i == 123);
49         ss >> i;
50         assert(i == 456);
51         ss << i << ' ' << 123;
52         assert(ss.str() == L"456 1236 ");
53         ss.str(L"5466 89 ");
54         ss >> i;
55         assert(i == 5466);
56         ss >> i;
57         assert(i == 89);
58         ss << i << ' ' << 321;
59         assert(ss.str() == L"89 3219 ");
60     }
61     {
62         std::stringstream ss;
63         ss.write("\xd1", 1);
64         assert(ss.str().length() == 1);
65     }
66 }
67