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 char* s, ios_base::openmode mode = ios_base::in);
17 
18 #include <fstream>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 
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("test.dat");
33         assert(fs.is_open());
34         fs >> c;
35         assert(c == 'r');
36     }
37     {
38         std::wifstream fs;
39         assert(!fs.is_open());
40         wchar_t c = L'a';
41         fs >> c;
42         assert(fs.fail());
43         assert(c == L'a');
44         fs.open("test.dat");
45         assert(fs.is_open());
46         fs >> c;
47         assert(c == L'r');
48     }
49 
50   return 0;
51 }
52