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, charT delim); 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* def** 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.good()); 36 assert(s == ""); 37 getline(in, s, '*'); 38 assert(in.eof()); 39 assert(s == " ghij"); 40 } 41 { 42 std::wistringstream in(L" abc* def** ghij"); 43 std::wstring s(L"initial text"); 44 getline(in, s, L'*'); 45 assert(in.good()); 46 assert(s == L" abc"); 47 getline(in, s, L'*'); 48 assert(in.good()); 49 assert(s == L" def"); 50 getline(in, s, L'*'); 51 assert(in.good()); 52 assert(s == L""); 53 getline(in, s, L'*'); 54 assert(in.eof()); 55 assert(s == L" ghij"); 56 } 57 #if TEST_STD_VER >= 11 58 { 59 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 60 std::istringstream in(" abc* def** ghij"); 61 S s("initial text"); 62 getline(in, s, '*'); 63 assert(in.good()); 64 assert(s == " abc"); 65 getline(in, s, '*'); 66 assert(in.good()); 67 assert(s == " def"); 68 getline(in, s, '*'); 69 assert(in.good()); 70 assert(s == ""); 71 getline(in, s, '*'); 72 assert(in.eof()); 73 assert(s == " ghij"); 74 } 75 { 76 typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S; 77 std::wistringstream in(L" abc* def** ghij"); 78 S s(L"initial text"); 79 getline(in, s, L'*'); 80 assert(in.good()); 81 assert(s == L" abc"); 82 getline(in, s, L'*'); 83 assert(in.good()); 84 assert(s == L" def"); 85 getline(in, s, L'*'); 86 assert(in.good()); 87 assert(s == L""); 88 getline(in, s, L'*'); 89 assert(in.eof()); 90 assert(s == L" ghij"); 91 } 92 #endif 93 } 94