xref: /llvm-project/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line_rv.pass.cpp (revision a8d1182f661ccecd99efd4e543fddf3172c67a95)
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);
15 
16 #include <string>
17 #include <sstream>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 
23 int main(int, char**)
24 {
25     {
26         std::string s("initial text");
27         getline(std::istringstream(" abc\n  def\n   ghij"), s);
28         assert(s == " abc");
29     }
30     {
31         std::wstring s(L"initial text");
32         getline(std::wistringstream(L" abc\n  def\n   ghij"), s);
33         assert(s == L" abc");
34     }
35     {
36         typedef std::basic_string<char, std::char_traits<char>, min_allocator<char> > S;
37         S s("initial text");
38         getline(std::istringstream(" abc\n  def\n   ghij"), s);
39         assert(s == " abc");
40     }
41     {
42         typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t> > S;
43         S s(L"initial text");
44         getline(std::wistringstream(L" abc\n  def\n   ghij"), s);
45         assert(s == L" abc");
46     }
47 
48   return 0;
49 }
50