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 // explicit basic_ofstream(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     static_assert(!std::is_convertible<fs::path, std::ofstream>::value,
29                   "ctor should be explicit");
30     static_assert(std::is_constructible<std::ofstream, fs::path const&,
31                                         std::ios_base::openmode>::value,
32                   "");
33   }
34   {
35     std::ofstream stream(p);
36     stream << 3.25;
37   }
38   {
39     std::ifstream stream(p);
40     double x = 0;
41     stream >> x;
42     assert(x == 3.25);
43   }
44   {
45     std::ifstream stream(p, std::ios_base::out);
46     double x = 0;
47     stream >> x;
48     assert(x == 3.25);
49   }
50   std::remove(p.c_str());
51   {
52     std::wofstream stream(p);
53     stream << 3.25;
54   }
55   {
56     std::wifstream stream(p);
57     double x = 0;
58     stream >> x;
59     assert(x == 3.25);
60   }
61   {
62     std::wifstream stream(p, std::ios_base::out);
63     double x = 0;
64     stream >> x;
65     assert(x == 3.25);
66   }
67   std::remove(p.c_str());
68 
69   return 0;
70 }
71