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