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 12 // <fstream> 13 14 // template <class charT, class traits = char_traits<charT> > 15 // class basic_ifstream 16 17 // explicit basic_ifstream(const filesystem::path& s, 18 // 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 namespace fs = std::filesystem; 27 28 int main(int, char**) { 29 { 30 fs::path p; 31 static_assert(!std::is_convertible<fs::path, std::ifstream>::value, 32 "ctor should be explicit"); 33 static_assert(std::is_constructible<std::ifstream, fs::path const&, 34 std::ios_base::openmode>::value, 35 ""); 36 } 37 { 38 std::ifstream fs(fs::path("test.dat")); 39 double x = 0; 40 fs >> x; 41 assert(x == 3.25); 42 } 43 // std::ifstream(const fs::path&, std::ios_base::openmode) is tested in 44 // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp 45 // which creates writable files. 46 { 47 std::wifstream fs(fs::path("test.dat")); 48 double x = 0; 49 fs >> x; 50 assert(x == 3.25); 51 } 52 // std::wifstream(const fs::path&, std::ios_base::openmode) is tested in 53 // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp 54 // which creates writable files. 55 56 return 0; 57 } 58