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 | // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM |
10 | |
11 | // <strstream> |
12 | |
13 | // class ostrstream |
14 | |
15 | // ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out); |
16 | |
17 | #include <strstream> |
18 | #include <cassert> |
19 | #include <string> |
20 | |
21 | #include "test_macros.h" |
22 | |
23 | int main(int, char**) |
24 | { |
25 | { |
26 | char buf[] = "123 4.5 dog" ; |
27 | std::ostrstream out(buf, 0); |
28 | assert(out.str() == std::string("123 4.5 dog" )); |
29 | int i = 321; |
30 | double d = 5.5; |
31 | std::string s("cat" ); |
32 | out << i << ' ' << d << ' ' << s << std::ends; |
33 | assert(out.str() == std::string("321 5.5 cat" )); |
34 | } |
35 | { |
36 | char buf[23] = "123 4.5 dog" ; |
37 | std::ostrstream out(buf, 11, std::ios::app); |
38 | assert(out.str() == std::string("123 4.5 dog" )); |
39 | int i = 321; |
40 | double d = 5.5; |
41 | std::string s("cat" ); |
42 | out << i << ' ' << d << ' ' << s << std::ends; |
43 | assert(out.str() == std::string("123 4.5 dog321 5.5 cat" )); |
44 | } |
45 | |
46 | return 0; |
47 | } |
48 | |