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 wchar_t* s, ios_base::openmode mode = ios_base::out);
15 
16 // This extension is only provided on Windows.
17 // REQUIRES: windows
18 // UNSUPPORTED: no-wide-characters
19 
20 // TODO: This should not be necessary
21 // ADDITIONAL_COMPILE_FLAGS:-D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT
22 
23 #include <fstream>
24 #include <cassert>
25 #include "test_macros.h"
26 #include "wide_temp_file.h"
27 
main(int,char **)28 int main(int, char**) {
29     std::wstring temp = get_wide_temp_file_name();
30     {
31         std::ofstream fs;
32         assert(!fs.is_open());
33         char c = 'a';
34         fs << c;
35         assert(fs.fail());
36         fs.open(temp.c_str());
37         assert(fs.is_open());
38         fs << c;
39     }
40     {
41         std::ifstream fs(temp.c_str());
42         char c = 0;
43         fs >> c;
44         assert(c == 'a');
45     }
46     _wremove(temp.c_str());
47     {
48         std::wofstream fs;
49         assert(!fs.is_open());
50         wchar_t c = L'a';
51         fs << c;
52         assert(fs.fail());
53         fs.open(temp.c_str());
54         assert(fs.is_open());
55         fs << c;
56     }
57     {
58         std::wifstream fs(temp.c_str());
59         wchar_t c = 0;
60         fs >> c;
61         assert(c == L'a');
62     }
63     _wremove(temp.c_str());
64 
65     return 0;
66 }
67