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 // explicit basic_ofstream(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(temp.c_str());
32         fs << 3.25;
33     }
34     {
35         std::ifstream fs(temp.c_str());
36         double x = 0;
37         fs >> x;
38         assert(x == 3.25);
39     }
40     {
41         std::ifstream fs(temp.c_str(), std::ios_base::out);
42         double x = 0;
43         fs >> x;
44         assert(x == 3.25);
45     }
46     _wremove(temp.c_str());
47     {
48         std::wofstream fs(temp.c_str());
49         fs << 3.25;
50     }
51     {
52         std::wifstream fs(temp.c_str());
53         double x = 0;
54         fs >> x;
55         assert(x == 3.25);
56     }
57     {
58         std::wifstream fs(temp.c_str(), std::ios_base::out);
59         double x = 0;
60         fs >> x;
61         assert(x == 3.25);
62     }
63     _wremove(temp.c_str());
64 
65     return 0;
66 }
67