• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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++03, c++11, c++14
10 // UNSUPPORTED: c++filesystem-disabled
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 "test_macros.h"
23 #include "platform_support.h"
24 
25 namespace fs = std::filesystem;
26 
main(int,char **)27 int main(int, char**) {
28   fs::path p = get_temp_file_name();
29   {
30     std::ofstream fs;
31     assert(!fs.is_open());
32     char c = 'a';
33     fs << c;
34     assert(fs.fail());
35     fs.open(p);
36     assert(fs.is_open());
37     fs << c;
38   }
39   {
40     std::ifstream fs(p.c_str());
41     char c = 0;
42     fs >> c;
43     assert(c == 'a');
44   }
45   std::remove(p.c_str());
46   {
47     std::wofstream fs;
48     assert(!fs.is_open());
49     wchar_t c = L'a';
50     fs << c;
51     assert(fs.fail());
52     fs.open(p);
53     assert(fs.is_open());
54     fs << c;
55   }
56   {
57     std::wifstream fs(p.c_str());
58     wchar_t c = 0;
59     fs >> c;
60     assert(c == L'a');
61   }
62   std::remove(p.c_str());
63 
64   return 0;
65 }
66