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 // explicit basic_istringstream(const basic_string<charT,traits,allocator>& str, 15 // ios_base::openmode which = ios_base::in); 16 17 #include <sstream> 18 #include <cassert> 19 20 int main(int, char**) 21 { 22 { 23 std::istringstream 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 } 33 { 34 std::istringstream ss(" 123 456", std::ios_base::out); 35 assert(ss.rdbuf() != 0); 36 assert(ss.good()); 37 assert(ss.str() == " 123 456"); 38 int i = 0; 39 ss >> i; 40 assert(i == 123); 41 ss >> i; 42 assert(i == 456); 43 } 44 { 45 std::wistringstream ss(L" 123 456"); 46 assert(ss.rdbuf() != 0); 47 assert(ss.good()); 48 assert(ss.str() == L" 123 456"); 49 int i = 0; 50 ss >> i; 51 assert(i == 123); 52 ss >> i; 53 assert(i == 456); 54 } 55 { 56 std::wistringstream ss(L" 123 456", std::ios_base::out); 57 assert(ss.rdbuf() != 0); 58 assert(ss.good()); 59 assert(ss.str() == L" 123 456"); 60 int i = 0; 61 ss >> i; 62 assert(i == 123); 63 ss >> i; 64 assert(i == 456); 65 } 66 67 return 0; 68 } 69