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