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