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 // <fstream>
10 
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_ifstream
13 
14 // void open(const char* s, ios_base::openmode mode = ios_base::in);
15 
16 #include <fstream>
17 #include <cassert>
18 
19 int main(int, char**)
20 {
21     {
22         std::ifstream fs;
23         assert(!fs.is_open());
24         char c = 'a';
25         fs >> c;
26         assert(fs.fail());
27         assert(c == 'a');
28         fs.open("test.dat");
29         assert(fs.is_open());
30         fs >> c;
31         assert(c == 'r');
32     }
33     {
34         std::wifstream fs;
35         assert(!fs.is_open());
36         wchar_t c = L'a';
37         fs >> c;
38         assert(fs.fail());
39         assert(c == L'a');
40         fs.open("test.dat");
41         assert(fs.is_open());
42         fs >> c;
43         assert(c == L'r');
44     }
45 
46   return 0;
47 }
48