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 strstream 14 15 // strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out); 16 17 #include <strstream> 18 #include <cassert> 19 #include <string> 20 21 #include "test_macros.h" 22 main(int,char **)23int main(int, char**) 24 { 25 { 26 char buf[] = "123 4.5 dog"; 27 std::strstream inout(buf, 0); 28 assert(inout.str() == std::string("123 4.5 dog")); 29 int i = 321; 30 double d = 5.5; 31 std::string s("cat"); 32 inout >> i; 33 assert(inout.fail()); 34 inout.clear(); 35 inout << i << ' ' << d << ' ' << s; 36 assert(inout.str() == std::string("321 5.5 cat")); 37 i = 0; 38 d = 0; 39 s = ""; 40 inout >> i >> d >> s; 41 assert(i == 321); 42 assert(d == 5.5); 43 assert(s == "cat"); 44 } 45 { 46 char buf[23] = "123 4.5 dog"; 47 std::strstream inout(buf, 11, std::ios::app); 48 assert(inout.str() == std::string("123 4.5 dog")); 49 int i = 0; 50 double d = 0; 51 std::string s; 52 inout >> i >> d >> s; 53 assert(i == 123); 54 assert(d == 4.5); 55 assert(s == "dog"); 56 i = 321; 57 d = 5.5; 58 s = "cat"; 59 inout.clear(); 60 inout << i << ' ' << d << ' ' << s; 61 assert(inout.str() == std::string("123 4.5 dog321 5.5 cat")); 62 } 63 64 return 0; 65 } 66