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: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}} 14 15 // <fstream> 16 17 // plate <class charT, class traits = char_traits<charT> > 18 // class basic_ofstream 19 20 // void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out); 21 22 #include <fstream> 23 #include <filesystem> 24 #include <cassert> 25 #include "test_macros.h" 26 #include "platform_support.h" 27 28 namespace fs = std::filesystem; 29 30 int main(int, char**) { 31 fs::path p = get_temp_file_name(); 32 { 33 std::ofstream fs; 34 assert(!fs.is_open()); 35 char c = 'a'; 36 fs << c; 37 assert(fs.fail()); 38 fs.open(p); 39 assert(fs.is_open()); 40 fs << c; 41 } 42 { 43 std::ifstream fs(p.c_str()); 44 char c = 0; 45 fs >> c; 46 assert(c == 'a'); 47 } 48 std::remove(p.string().c_str()); 49 { 50 std::wofstream fs; 51 assert(!fs.is_open()); 52 wchar_t c = L'a'; 53 fs << c; 54 assert(fs.fail()); 55 fs.open(p); 56 assert(fs.is_open()); 57 fs << c; 58 } 59 { 60 std::wifstream fs(p.c_str()); 61 wchar_t c = 0; 62 fs >> c; 63 assert(c == L'a'); 64 } 65 std::remove(p.string().c_str()); 66 67 return 0; 68 } 69