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_istringstream 13 14 // void str(const basic_string<charT,traits,Allocator>& s); 15 16 #include <sstream> 17 #include <cassert> 18 19 int main(int, char**) 20 { 21 { 22 std::istringstream ss(" 123 456"); 23 assert(ss.rdbuf() != 0); 24 assert(ss.good()); 25 assert(ss.str() == " 123 456"); 26 int i = 0; 27 ss >> i; 28 assert(i == 123); 29 ss >> i; 30 assert(i == 456); 31 ss.str(" 789"); 32 ss.clear(); 33 assert(ss.good()); 34 assert(ss.str() == " 789"); 35 ss >> i; 36 assert(i == 789); 37 } 38 { 39 std::wistringstream ss(L" 123 456"); 40 assert(ss.rdbuf() != 0); 41 assert(ss.good()); 42 assert(ss.str() == L" 123 456"); 43 int i = 0; 44 ss >> i; 45 assert(i == 123); 46 ss >> i; 47 assert(i == 456); 48 ss.str(L" 789"); 49 ss.clear(); 50 assert(ss.good()); 51 assert(ss.str() == L" 789"); 52 ss >> i; 53 assert(i == 789); 54 } 55 56 return 0; 57 } 58