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 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
43 {
44 std::wostringstream ss(L" 123 456");
45 assert(ss.rdbuf() != 0);
46 assert(ss.good());
47 assert(ss.str() == L" 123 456");
48 int i = 234;
49 ss << i << ' ' << 567;
50 assert(ss.str() == L"234 5676");
51 }
52 {
53 std::wostringstream ss(L" 123 456", std::ios_base::in);
54 assert(ss.rdbuf() != 0);
55 assert(ss.good());
56 assert(ss.str() == L" 123 456");
57 int i = 234;
58 ss << i << ' ' << 567;
59 assert(ss.str() == L"234 5676");
60 }
61 #endif
62
63 return 0;
64 }
65