xref: /llvm-project/libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/open_string.pass.cpp (revision f4c1258d5633fcf06385ff3fd1f4bf57ab971964)
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 // FILE_DEPENDENCIES: test.dat
10 
11 // <fstream>
12 
13 // template <class charT, class traits = char_traits<charT> >
14 // class basic_ifstream
15 
16 // void open(const string& s, ios_base::openmode mode = ios_base::in);
17 
18 #include <fstream>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 
main(int,char **)23 int main(int, char**)
24 {
25     {
26         std::ifstream fs;
27         assert(!fs.is_open());
28         char c = 'a';
29         fs >> c;
30         assert(fs.fail());
31         assert(c == 'a');
32         fs.open(std::string("test.dat"));
33         assert(fs.is_open());
34         fs >> c;
35         assert(c == 'r');
36     }
37 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
38     {
39         std::wifstream fs;
40         assert(!fs.is_open());
41         wchar_t c = L'a';
42         fs >> c;
43         assert(fs.fail());
44         assert(c == L'a');
45         fs.open(std::string("test.dat"));
46         assert(fs.is_open());
47         fs >> c;
48         assert(c == L'r');
49     }
50 #endif
51 
52   return 0;
53 }
54