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 // plate <class charT, class traits = char_traits<charT> > 15 // class basic_ofstream 16 17 // void open(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 main()26int main() { 27 fs::path p = get_temp_file_name(); 28 { 29 std::ofstream fs; 30 assert(!fs.is_open()); 31 char c = 'a'; 32 fs << c; 33 assert(fs.fail()); 34 fs.open(p); 35 assert(fs.is_open()); 36 fs << c; 37 } 38 { 39 std::ifstream fs(p.c_str()); 40 char c = 0; 41 fs >> c; 42 assert(c == 'a'); 43 } 44 std::remove(p.c_str()); 45 { 46 std::wofstream fs; 47 assert(!fs.is_open()); 48 wchar_t c = L'a'; 49 fs << c; 50 assert(fs.fail()); 51 fs.open(p); 52 assert(fs.is_open()); 53 fs << c; 54 } 55 { 56 std::wifstream fs(p.c_str()); 57 wchar_t c = 0; 58 fs >> c; 59 assert(c == L'a'); 60 } 61 std::remove(p.c_str()); 62 } 63