path.pass.cpp (1614B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03, c++11, c++14 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 namespace fs = std::filesystem; 25 26 int main() { 27 { 28 fs::path p; 29 static_assert(!std::is_convertible<fs::path, std::ifstream>::value, 30 "ctor should be explicit"); 31 static_assert(std::is_constructible<std::ifstream, fs::path const&, 32 std::ios_base::openmode>::value, 33 ""); 34 } 35 { 36 std::ifstream fs(fs::path("test.dat")); 37 double x = 0; 38 fs >> x; 39 assert(x == 3.25); 40 } 41 // std::ifstream(const fs::path&, std::ios_base::openmode) is tested in 42 // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp 43 // which creates writable files. 44 { 45 std::wifstream fs(fs::path("test.dat")); 46 double x = 0; 47 fs >> x; 48 assert(x == 3.25); 49 } 50 // std::wifstream(const fs::path&, std::ios_base::openmode) is tested in 51 // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp 52 // which creates writable files. 53 }