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_ostringstream 14 15 // explicit basic_ostringstream(const basic_string<charT,traits,allocator>& str, 16 // ios_base::openmode which = ios_base::in); 17 18 #include <sstream> 19 #include <cassert> 20 main()21int main() 22 { 23 { 24 std::ostringstream ss(" 123 456"); 25 assert(ss.rdbuf() != 0); 26 assert(ss.good()); 27 assert(ss.str() == " 123 456"); 28 int i = 234; 29 ss << i << ' ' << 567; 30 assert(ss.str() == "234 5676"); 31 } 32 { 33 std::ostringstream ss(" 123 456", std::ios_base::in); 34 assert(ss.rdbuf() != 0); 35 assert(ss.good()); 36 assert(ss.str() == " 123 456"); 37 int i = 234; 38 ss << i << ' ' << 567; 39 assert(ss.str() == "234 5676"); 40 } 41 { 42 std::wostringstream ss(L" 123 456"); 43 assert(ss.rdbuf() != 0); 44 assert(ss.good()); 45 assert(ss.str() == L" 123 456"); 46 int i = 234; 47 ss << i << ' ' << 567; 48 assert(ss.str() == L"234 5676"); 49 } 50 { 51 std::wostringstream ss(L" 123 456", std::ios_base::in); 52 assert(ss.rdbuf() != 0); 53 assert(ss.good()); 54 assert(ss.str() == L" 123 456"); 55 int i = 234; 56 ss << i << ' ' << 567; 57 assert(ss.str() == L"234 5676"); 58 } 59 } 60