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// XFAIL: FROZEN-CXX03-HEADERS-FIXME
18
19#include <sstream>
20#include <cassert>
21
22#include "test_macros.h"
23#include "operator_hijacker.h"
24
25int main(int, char**)
26{
27 {
28 std::istringstream ss(" 123 456");
29 assert(ss.rdbuf() != nullptr);
30 assert(ss.good());
31 assert(ss.str() == " 123 456");
32 int i = 0;
33 ss >> i;
34 assert(i == 123);
35 ss >> i;
36 assert(i == 456);
37 }
38 {
39 std::basic_istringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(" 123 456");
40 assert(ss.rdbuf() != nullptr);
41 assert(ss.good());
42 assert(ss.str() == " 123 456");
43 int i = 0;
44 ss >> i;
45 assert(i == 123);
46 ss >> i;
47 assert(i == 456);
48 }
49 {
50 std::istringstream ss(" 123 456", std::ios_base::out);
51 assert(ss.rdbuf() != nullptr);
52 assert(ss.good());
53 assert(ss.str() == " 123 456");
54 int i = 0;
55 ss >> i;
56 assert(i == 123);
57 ss >> i;
58 assert(i == 456);
59 }
60 {
61 std::basic_istringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(
62 " 123 456", std::ios_base::out);
63 assert(ss.rdbuf() != nullptr);
64 assert(ss.good());
65 assert(ss.str() == " 123 456");
66 int i = 0;
67 ss >> i;
68 assert(i == 123);
69 ss >> i;
70 assert(i == 456);
71 }
72#ifndef TEST_HAS_NO_WIDE_CHARACTERS
73 {
74 std::wistringstream ss(L" 123 456");
75 assert(ss.rdbuf() != nullptr);
76 assert(ss.good());
77 assert(ss.str() == L" 123 456");
78 int i = 0;
79 ss >> i;
80 assert(i == 123);
81 ss >> i;
82 assert(i == 456);
83 }
84 {
85 std::basic_istringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(
86 L" 123 456");
87 assert(ss.rdbuf() != nullptr);
88 assert(ss.good());
89 assert(ss.str() == L" 123 456");
90 int i = 0;
91 ss >> i;
92 assert(i == 123);
93 ss >> i;
94 assert(i == 456);
95 }
96 {
97 std::wistringstream ss(L" 123 456", std::ios_base::out);
98 assert(ss.rdbuf() != nullptr);
99 assert(ss.good());
100 assert(ss.str() == L" 123 456");
101 int i = 0;
102 ss >> i;
103 assert(i == 123);
104 ss >> i;
105 assert(i == 456);
106 }
107 {
108 std::basic_istringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(
109 L" 123 456", std::ios_base::out);
110 assert(ss.rdbuf() != nullptr);
111 assert(ss.good());
112 assert(ss.str() == L" 123 456");
113 int i = 0;
114 ss >> i;
115 assert(i == 123);
116 ss >> i;
117 assert(i == 456);
118 }
119#endif
120
121 return 0;
122}
123

source code of libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string.pass.cpp