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: with_system_cxx_lib=macosx10.14 14 // UNSUPPORTED: with_system_cxx_lib=macosx10.13 15 // UNSUPPORTED: with_system_cxx_lib=macosx10.12 16 // UNSUPPORTED: with_system_cxx_lib=macosx10.11 17 // UNSUPPORTED: with_system_cxx_lib=macosx10.10 18 // UNSUPPORTED: with_system_cxx_lib=macosx10.9 19 20 // <fstream> 21 22 // plate <class charT, class traits = char_traits<charT> > 23 // class basic_ofstream 24 25 // explicit basic_ofstream(const filesystem::path& s, ios_base::openmode mode = ios_base::out); 26 27 #include <fstream> 28 #include <filesystem> 29 #include <cassert> 30 #include "test_macros.h" 31 #include "platform_support.h" 32 33 namespace fs = std::filesystem; 34 35 int main(int, char**) { 36 fs::path p = get_temp_file_name(); 37 { 38 static_assert(!std::is_convertible<fs::path, std::ofstream>::value, 39 "ctor should be explicit"); 40 static_assert(std::is_constructible<std::ofstream, fs::path const&, 41 std::ios_base::openmode>::value, 42 ""); 43 } 44 { 45 std::ofstream stream(p); 46 stream << 3.25; 47 } 48 { 49 std::ifstream stream(p); 50 double x = 0; 51 stream >> x; 52 assert(x == 3.25); 53 } 54 { 55 std::ifstream stream(p, std::ios_base::out); 56 double x = 0; 57 stream >> x; 58 assert(x == 3.25); 59 } 60 std::remove(p.string().c_str()); 61 { 62 std::wofstream stream(p); 63 stream << 3.25; 64 } 65 { 66 std::wifstream stream(p); 67 double x = 0; 68 stream >> x; 69 assert(x == 3.25); 70 } 71 { 72 std::wifstream stream(p, std::ios_base::out); 73 double x = 0; 74 stream >> x; 75 assert(x == 3.25); 76 } 77 std::remove(p.string().c_str()); 78 79 return 0; 80 } 81