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_stringstream 13 14 // void str(const basic_string<charT,traits,Allocator>& str); 15 16 #include <sstream> 17 #include <cassert> 18 19 #include "test_macros.h" 20 main(int,char **)21int main(int, char**) 22 { 23 { 24 std::stringstream ss(" 123 456 "); 25 assert(ss.rdbuf() != 0); 26 assert(ss.good()); 27 assert(ss.str() == " 123 456 "); 28 int i = 0; 29 ss >> i; 30 assert(i == 123); 31 ss >> i; 32 assert(i == 456); 33 ss << i << ' ' << 123; 34 assert(ss.str() == "456 1236 "); 35 ss.str("5466 89 "); 36 ss >> i; 37 assert(i == 5466); 38 ss >> i; 39 assert(i == 89); 40 ss << i << ' ' << 321; 41 assert(ss.str() == "89 3219 "); 42 } 43 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 44 { 45 std::wstringstream ss(L" 123 456 "); 46 assert(ss.rdbuf() != 0); 47 assert(ss.good()); 48 assert(ss.str() == L" 123 456 "); 49 int i = 0; 50 ss >> i; 51 assert(i == 123); 52 ss >> i; 53 assert(i == 456); 54 ss << i << ' ' << 123; 55 assert(ss.str() == L"456 1236 "); 56 ss.str(L"5466 89 "); 57 ss >> i; 58 assert(i == 5466); 59 ss >> i; 60 assert(i == 89); 61 ss << i << ' ' << 321; 62 assert(ss.str() == L"89 3219 "); 63 } 64 #endif 65 { 66 std::stringstream ss; 67 ss.write("\xd1", 1); 68 assert(ss.str().length() == 1); 69 } 70 71 return 0; 72 } 73