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 #include "test_macros.h"
21
main(int,char **)22 int main(int, char**)
23 {
24 {
25 std::ostringstream ss(" 123 456");
26 assert(ss.rdbuf() != 0);
27 assert(ss.good());
28 assert(ss.str() == " 123 456");
29 int i = 234;
30 ss << i << ' ' << 567;
31 assert(ss.str() == "234 5676");
32 }
33 {
34 std::ostringstream ss(" 123 456", std::ios_base::in);
35 assert(ss.rdbuf() != 0);
36 assert(ss.good());
37 assert(ss.str() == " 123 456");
38 int i = 234;
39 ss << i << ' ' << 567;
40 assert(ss.str() == "234 5676");
41 }
42 {
43 std::wostringstream ss(L" 123 456");
44 assert(ss.rdbuf() != 0);
45 assert(ss.good());
46 assert(ss.str() == L" 123 456");
47 int i = 234;
48 ss << i << ' ' << 567;
49 assert(ss.str() == L"234 5676");
50 }
51 {
52 std::wostringstream ss(L" 123 456", std::ios_base::in);
53 assert(ss.rdbuf() != 0);
54 assert(ss.good());
55 assert(ss.str() == L" 123 456");
56 int i = 234;
57 ss << i << ' ' << 567;
58 assert(ss.str() == L"234 5676");
59 }
60
61 return 0;
62 }
63