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 #include <fstream>
17 #include <cassert>
18 #include "test_macros.h"
19 #include "platform_support.h"
20 
main(int,char **)21 int main(int, char**)
22 {
23 #ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
24     std::wstring temp = get_wide_temp_file_name();
25     {
26         std::ofstream fs;
27         assert(!fs.is_open());
28         char c = 'a';
29         fs << c;
30         assert(fs.fail());
31         fs.open(temp.c_str());
32         assert(fs.is_open());
33         fs << c;
34     }
35     {
36         std::ifstream fs(temp.c_str());
37         char c = 0;
38         fs >> c;
39         assert(c == 'a');
40     }
41     _wremove(temp.c_str());
42     {
43         std::wofstream fs;
44         assert(!fs.is_open());
45         wchar_t c = L'a';
46         fs << c;
47         assert(fs.fail());
48         fs.open(temp.c_str());
49         assert(fs.is_open());
50         fs << c;
51     }
52     {
53         std::wifstream fs(temp.c_str());
54         wchar_t c = 0;
55         fs >> c;
56         assert(c == L'a');
57     }
58     _wremove(temp.c_str());
59 #endif
60 
61   return 0;
62 }
63