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_istringstream 14 15 // explicit basic_istringstream(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::istringstream 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 } 34 { 35 std::istringstream ss(" 123 456", std::ios_base::out); 36 assert(ss.rdbuf() != 0); 37 assert(ss.good()); 38 assert(ss.str() == " 123 456"); 39 int i = 0; 40 ss >> i; 41 assert(i == 123); 42 ss >> i; 43 assert(i == 456); 44 } 45 { 46 std::wistringstream ss(L" 123 456"); 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 } 56 { 57 std::wistringstream ss(L" 123 456", std::ios_base::out); 58 assert(ss.rdbuf() != 0); 59 assert(ss.good()); 60 assert(ss.str() == L" 123 456"); 61 int i = 0; 62 ss >> i; 63 assert(i == 123); 64 ss >> i; 65 assert(i == 456); 66 } 67 } 68