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 // template <class charT, class traits, class Allocator> 15 // void 16 // swap(basic_stringstream<charT, traits, Allocator>& x, 17 // basic_stringstream<charT, traits, Allocator>& y); 18 19 #include <sstream> 20 #include <cassert> 21 22 #include "test_macros.h" 23 24 int main(int, char**) 25 { 26 { 27 std::stringstream ss0(" 123 456 "); 28 std::stringstream ss; 29 swap(ss, ss0); 30 assert(ss.rdbuf() != 0); 31 assert(ss.good()); 32 assert(ss.str() == " 123 456 "); 33 int i = 0; 34 ss >> i; 35 assert(i == 123); 36 ss >> i; 37 assert(i == 456); 38 ss << i << ' ' << 123; 39 assert(ss.str() == "456 1236 "); 40 ss0 << i << ' ' << 123; 41 assert(ss0.str() == "456 123"); 42 } 43 { 44 std::wstringstream ss0(L" 123 456 "); 45 std::wstringstream ss; 46 swap(ss, ss0); 47 assert(ss.rdbuf() != 0); 48 assert(ss.good()); 49 assert(ss.str() == L" 123 456 "); 50 int i = 0; 51 ss >> i; 52 assert(i == 123); 53 ss >> i; 54 assert(i == 456); 55 ss << i << ' ' << 123; 56 assert(ss.str() == L"456 1236 "); 57 ss0 << i << ' ' << 123; 58 assert(ss0.str() == L"456 123"); 59 } 60 61 return 0; 62 } 63