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 // <string>
11
12 // template<class charT, class traits, class Allocator>
13 // basic_istream<charT,traits>&
14 // operator>>(basic_istream<charT,traits>& is,
15 // basic_string<charT,traits,Allocator>& str);
16
17 #include <string>
18 #include <sstream>
19 #include <cassert>
20
21 #include "min_allocator.h"
22
main()23 int main()
24 {
25 {
26 std::istringstream in("a bc defghij");
27 std::string s("initial text");
28 in >> s;
29 assert(in.good());
30 assert(s == "a");
31 assert(in.peek() == ' ');
32 in >> s;
33 assert(in.good());
34 assert(s == "bc");
35 assert(in.peek() == ' ');
36 in.width(3);
37 in >> s;
38 assert(in.good());
39 assert(s == "def");
40 assert(in.peek() == 'g');
41 in >> s;
42 assert(in.eof());
43 assert(s == "ghij");
44 in >> s;
45 assert(in.fail());
46 }
47 {
48 std::wistringstream in(L"a bc defghij");
49 std::wstring s(L"initial text");
50 in >> s;
51 assert(in.good());
52 assert(s == L"a");
53 assert(in.peek() == L' ');
54 in >> s;
55 assert(in.good());
56 assert(s == L"bc");
57 assert(in.peek() == L' ');
58 in.width(3);
59 in >> s;
60 assert(in.good());
61 assert(s == L"def");
62 assert(in.peek() == L'g');
63 in >> s;
64 assert(in.eof());
65 assert(s == L"ghij");
66 in >> s;
67 assert(in.fail());
68 }
69 #if __cplusplus >= 201103L
70 {
71 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
72 std::istringstream in("a bc defghij");
73 S s("initial text");
74 in >> s;
75 assert(in.good());
76 assert(s == "a");
77 assert(in.peek() == ' ');
78 in >> s;
79 assert(in.good());
80 assert(s == "bc");
81 assert(in.peek() == ' ');
82 in.width(3);
83 in >> s;
84 assert(in.good());
85 assert(s == "def");
86 assert(in.peek() == 'g');
87 in >> s;
88 assert(in.eof());
89 assert(s == "ghij");
90 in >> s;
91 assert(in.fail());
92 }
93 {
94 typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
95 std::wistringstream in(L"a bc defghij");
96 S s(L"initial text");
97 in >> s;
98 assert(in.good());
99 assert(s == L"a");
100 assert(in.peek() == L' ');
101 in >> s;
102 assert(in.good());
103 assert(s == L"bc");
104 assert(in.peek() == L' ');
105 in.width(3);
106 in >> s;
107 assert(in.good());
108 assert(s == L"def");
109 assert(in.peek() == L'g');
110 in >> s;
111 assert(in.eof());
112 assert(s == L"ghij");
113 in >> s;
114 assert(in.fail());
115 }
116 #endif
117 }
118