Home | History | Annotate | Download | only in string.io
      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 int main()
     22 {
     23     {
     24         std::istringstream in("a bc defghij");
     25         std::string s("initial text");
     26         in >> s;
     27         assert(in.good());
     28         assert(s == "a");
     29         assert(in.peek() == ' ');
     30         in >> s;
     31         assert(in.good());
     32         assert(s == "bc");
     33         assert(in.peek() == ' ');
     34         in.width(3);
     35         in >> s;
     36         assert(in.good());
     37         assert(s == "def");
     38         assert(in.peek() == 'g');
     39         in >> s;
     40         assert(in.eof());
     41         assert(s == "ghij");
     42         in >> s;
     43         assert(in.fail());
     44     }
     45     {
     46         std::wistringstream in(L"a bc defghij");
     47         std::wstring s(L"initial text");
     48         in >> s;
     49         assert(in.good());
     50         assert(s == L"a");
     51         assert(in.peek() == L' ');
     52         in >> s;
     53         assert(in.good());
     54         assert(s == L"bc");
     55         assert(in.peek() == L' ');
     56         in.width(3);
     57         in >> s;
     58         assert(in.good());
     59         assert(s == L"def");
     60         assert(in.peek() == L'g');
     61         in >> s;
     62         assert(in.eof());
     63         assert(s == L"ghij");
     64         in >> s;
     65         assert(in.fail());
     66     }
     67 }
     68