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 // <string> 10 11 // template<class charT, class traits, class Allocator> 12 // basic_istream<charT,traits>& 13 // getline(basic_istream<charT,traits>& is, 14 // basic_string<charT,traits,Allocator>& str, charT delim); 15 16 #include <string> 17 #include <sstream> 18 #include <cassert> 19 20 #include "min_allocator.h" 21 22 int main(int, char**) 23 { 24 { 25 std::istringstream in(" abc* def** ghij"); 26 std::string s("initial text"); 27 getline(in, s, '*'); 28 assert(in.good()); 29 assert(s == " abc"); 30 getline(in, s, '*'); 31 assert(in.good()); 32 assert(s == " def"); 33 getline(in, s, '*'); 34 assert(in.good()); 35 assert(s == ""); 36 getline(in, s, '*'); 37 assert(in.eof()); 38 assert(s == " ghij"); 39 } 40 { 41 std::wistringstream in(L" abc* def** ghij"); 42 std::wstring s(L"initial text"); 43 getline(in, s, L'*'); 44 assert(in.good()); 45 assert(s == L" abc"); 46 getline(in, s, L'*'); 47 assert(in.good()); 48 assert(s == L" def"); 49 getline(in, s, L'*'); 50 assert(in.good()); 51 assert(s == L""); 52 getline(in, s, L'*'); 53 assert(in.eof()); 54 assert(s == L" ghij"); 55 } 56 #if TEST_STD_VER >= 11 57 { 58 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 59 std::istringstream in(" abc* def** ghij"); 60 S s("initial text"); 61 getline(in, s, '*'); 62 assert(in.good()); 63 assert(s == " abc"); 64 getline(in, s, '*'); 65 assert(in.good()); 66 assert(s == " def"); 67 getline(in, s, '*'); 68 assert(in.good()); 69 assert(s == ""); 70 getline(in, s, '*'); 71 assert(in.eof()); 72 assert(s == " ghij"); 73 } 74 { 75 typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S; 76 std::wistringstream in(L" abc* def** ghij"); 77 S s(L"initial text"); 78 getline(in, s, L'*'); 79 assert(in.good()); 80 assert(s == L" abc"); 81 getline(in, s, L'*'); 82 assert(in.good()); 83 assert(s == L" def"); 84 getline(in, s, L'*'); 85 assert(in.good()); 86 assert(s == L""); 87 getline(in, s, L'*'); 88 assert(in.eof()); 89 assert(s == L" ghij"); 90 } 91 #endif 92 93 return 0; 94 } 95