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_ostringstream
13 
14 // explicit basic_ostringstream(const basic_string<charT,traits,allocator>& str,
15 //                              ios_base::openmode which = ios_base::in);
16 
17 #include <sstream>
18 #include <cassert>
19 
20 int main(int, char**)
21 {
22     {
23         std::ostringstream ss(" 123 456");
24         assert(ss.rdbuf() != 0);
25         assert(ss.good());
26         assert(ss.str() == " 123 456");
27         int i = 234;
28         ss << i << ' ' << 567;
29         assert(ss.str() == "234 5676");
30     }
31     {
32         std::ostringstream ss(" 123 456", std::ios_base::in);
33         assert(ss.rdbuf() != 0);
34         assert(ss.good());
35         assert(ss.str() == " 123 456");
36         int i = 234;
37         ss << i << ' ' << 567;
38         assert(ss.str() == "234 5676");
39     }
40     {
41         std::wostringstream ss(L" 123 456");
42         assert(ss.rdbuf() != 0);
43         assert(ss.good());
44         assert(ss.str() == L" 123 456");
45         int i = 234;
46         ss << i << ' ' << 567;
47         assert(ss.str() == L"234 5676");
48     }
49     {
50         std::wostringstream ss(L" 123 456", std::ios_base::in);
51         assert(ss.rdbuf() != 0);
52         assert(ss.good());
53         assert(ss.str() == L" 123 456");
54         int i = 234;
55         ss << i << ' ' << 567;
56         assert(ss.str() == L"234 5676");
57     }
58 
59   return 0;
60 }
61