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 //   getline(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 
     23 int main()
     24 {
     25     {
     26         std::istringstream in(" abc\n  def\n   ghij");
     27         std::string s("initial text");
     28         getline(in, s);
     29         assert(in.good());
     30         assert(s == " abc");
     31         getline(in, s);
     32         assert(in.good());
     33         assert(s == "  def");
     34         getline(in, s);
     35         assert(in.eof());
     36         assert(s == "   ghij");
     37     }
     38     {
     39         std::wistringstream in(L" abc\n  def\n   ghij");
     40         std::wstring s(L"initial text");
     41         getline(in, s);
     42         assert(in.good());
     43         assert(s == L" abc");
     44         getline(in, s);
     45         assert(in.good());
     46         assert(s == L"  def");
     47         getline(in, s);
     48         assert(in.eof());
     49         assert(s == L"   ghij");
     50     }
     51 #if __cplusplus >= 201103L
     52     {
     53         typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
     54         std::istringstream in(" abc\n  def\n   ghij");
     55         S s("initial text");
     56         getline(in, s);
     57         assert(in.good());
     58         assert(s == " abc");
     59         getline(in, s);
     60         assert(in.good());
     61         assert(s == "  def");
     62         getline(in, s);
     63         assert(in.eof());
     64         assert(s == "   ghij");
     65     }
     66     {
     67         typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
     68         std::wistringstream in(L" abc\n  def\n   ghij");
     69         S s(L"initial text");
     70         getline(in, s);
     71         assert(in.good());
     72         assert(s == L" abc");
     73         getline(in, s);
     74         assert(in.good());
     75         assert(s == L"  def");
     76         getline(in, s);
     77         assert(in.eof());
     78         assert(s == L"   ghij");
     79     }
     80 #endif
     81 }
     82