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 // UNSUPPORTED: libcpp-has-no-filesystem-library 11 12 // Filesystem is supported on Apple platforms starting with macosx10.15. 13 // UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}} 14 15 // FILE_DEPENDENCIES: test.dat 16 17 // <fstream> 18 19 // template <class charT, class traits = char_traits<charT> > 20 // class basic_ifstream 21 22 // explicit basic_ifstream(const filesystem::path& s, 23 // ios_base::openmode mode = ios_base::in); 24 25 #include <fstream> 26 #include <filesystem> 27 #include <cassert> 28 29 #include "test_macros.h" 30 31 namespace fs = std::filesystem; 32 33 int main(int, char**) { 34 { 35 fs::path p; 36 static_assert(!std::is_convertible<fs::path, std::ifstream>::value, 37 "ctor should be explicit"); 38 static_assert(std::is_constructible<std::ifstream, fs::path const&, 39 std::ios_base::openmode>::value, 40 ""); 41 } 42 { 43 std::ifstream fs(fs::path("test.dat")); 44 double x = 0; 45 fs >> x; 46 assert(x == 3.25); 47 } 48 // std::ifstream(const fs::path&, std::ios_base::openmode) is tested in 49 // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp 50 // which creates writable files. 51 52 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 53 { 54 std::wifstream fs(fs::path("test.dat")); 55 double x = 0; 56 fs >> x; 57 assert(x == 3.25); 58 } 59 // std::wifstream(const fs::path&, std::ios_base::openmode) is tested in 60 // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp 61 // which creates writable files. 62 #endif 63 64 return 0; 65 } 66