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