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 #include "test_macros.h" 21 22 int main(int, char**) 23 { 24 { 25 std::istringstream ss(" 123 456"); 26 assert(ss.rdbuf() != 0); 27 assert(ss.good()); 28 assert(ss.str() == " 123 456"); 29 int i = 0; 30 ss >> i; 31 assert(i == 123); 32 ss >> i; 33 assert(i == 456); 34 } 35 { 36 std::istringstream ss(" 123 456", std::ios_base::out); 37 assert(ss.rdbuf() != 0); 38 assert(ss.good()); 39 assert(ss.str() == " 123 456"); 40 int i = 0; 41 ss >> i; 42 assert(i == 123); 43 ss >> i; 44 assert(i == 456); 45 } 46 { 47 std::wistringstream ss(L" 123 456"); 48 assert(ss.rdbuf() != 0); 49 assert(ss.good()); 50 assert(ss.str() == L" 123 456"); 51 int i = 0; 52 ss >> i; 53 assert(i == 123); 54 ss >> i; 55 assert(i == 456); 56 } 57 { 58 std::wistringstream ss(L" 123 456", std::ios_base::out); 59 assert(ss.rdbuf() != 0); 60 assert(ss.good()); 61 assert(ss.str() == L" 123 456"); 62 int i = 0; 63 ss >> i; 64 assert(i == 123); 65 ss >> i; 66 assert(i == 456); 67 } 68 69 return 0; 70 } 71