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