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