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: no-filesystem 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 main(int,char **)30int 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 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 51 { 52 std::wofstream fs; 53 assert(!fs.is_open()); 54 wchar_t c = L'a'; 55 fs << c; 56 assert(fs.fail()); 57 fs.open(p); 58 assert(fs.is_open()); 59 fs << c; 60 } 61 { 62 std::wifstream fs(p.c_str()); 63 wchar_t c = 0; 64 fs >> c; 65 assert(c == L'a'); 66 } 67 std::remove(p.string().c_str()); 68 #endif 69 70 return 0; 71 } 72