1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <sstream> 11 12 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 13 // class basic_stringstream 14 15 // void str(const basic_string<charT,traits,Allocator>& str); 16 17 #include <sstream> 18 #include <cassert> 19 main()20int main() 21 { 22 { 23 std::stringstream ss(" 123 456 "); 24 assert(ss.rdbuf() != 0); 25 assert(ss.good()); 26 assert(ss.str() == " 123 456 "); 27 int i = 0; 28 ss >> i; 29 assert(i == 123); 30 ss >> i; 31 assert(i == 456); 32 ss << i << ' ' << 123; 33 assert(ss.str() == "456 1236 "); 34 ss.str("5466 89 "); 35 ss >> i; 36 assert(i == 5466); 37 ss >> i; 38 assert(i == 89); 39 ss << i << ' ' << 321; 40 assert(ss.str() == "89 3219 "); 41 } 42 { 43 std::wstringstream ss(L" 123 456 "); 44 assert(ss.rdbuf() != 0); 45 assert(ss.good()); 46 assert(ss.str() == L" 123 456 "); 47 int i = 0; 48 ss >> i; 49 assert(i == 123); 50 ss >> i; 51 assert(i == 456); 52 ss << i << ' ' << 123; 53 assert(ss.str() == L"456 1236 "); 54 ss.str(L"5466 89 "); 55 ss >> i; 56 assert(i == 5466); 57 ss >> i; 58 assert(i == 89); 59 ss << i << ' ' << 321; 60 assert(ss.str() == L"89 3219 "); 61 } 62 } 63