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