Home | History | Annotate | Download | only in stringstream.cons
      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 // explicit basic_stringstream(const basic_string<charT,traits,Allocator>& str,
     16 //                             ios_base::openmode which = ios_base::out|ios_base::in);
     17 
     18 #include <sstream>
     19 #include <cassert>
     20 
     21 int main()
     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     }
     36     {
     37         std::wstringstream ss(L" 123 456 ");
     38         assert(ss.rdbuf() != 0);
     39         assert(ss.good());
     40         assert(ss.str() == L" 123 456 ");
     41         int i = 0;
     42         ss >> i;
     43         assert(i == 123);
     44         ss >> i;
     45         assert(i == 456);
     46         ss << i << ' ' << 123;
     47         assert(ss.str() == L"456 1236 ");
     48     }
     49 }
     50