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