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 swap(basic_stringstream& rhs); 15 16 #include <sstream> 17 #include <cassert> 18 19 int main(int, char**) 20 { 21 { 22 std::stringstream ss0(" 123 456 "); 23 std::stringstream ss; 24 ss.swap(ss0); 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 ss0 << i << ' ' << 123; 36 assert(ss0.str() == "456 123"); 37 } 38 { 39 std::wstringstream ss0(L" 123 456 "); 40 std::wstringstream ss; 41 ss.swap(ss0); 42 assert(ss.rdbuf() != 0); 43 assert(ss.good()); 44 assert(ss.str() == L" 123 456 "); 45 int i = 0; 46 ss >> i; 47 assert(i == 123); 48 ss >> i; 49 assert(i == 456); 50 ss << i << ' ' << 123; 51 assert(ss.str() == L"456 1236 "); 52 ss0 << i << ' ' << 123; 53 assert(ss0.str() == L"456 123"); 54 } 55 56 return 0; 57 } 58