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: libcpp-has-no-filesystem-library
11 
12 // Filesystem is supported on Apple platforms starting with macosx10.15.
13 // UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
14 
15 // <fstream>
16 
17 // plate <class charT, class traits = char_traits<charT> >
18 // class basic_ofstream
19 
20 // explicit basic_ofstream(const filesystem::path& s, ios_base::openmode mode = ios_base::out);
21 
22 #include <fstream>
23 #include <filesystem>
24 #include <cassert>
25 #include "test_macros.h"
26 #include "platform_support.h"
27 
28 namespace fs = std::filesystem;
29 
30 int main(int, char**) {
31   fs::path p = get_temp_file_name();
32   {
33     static_assert(!std::is_convertible<fs::path, std::ofstream>::value,
34                   "ctor should be explicit");
35     static_assert(std::is_constructible<std::ofstream, fs::path const&,
36                                         std::ios_base::openmode>::value,
37                   "");
38   }
39   {
40     std::ofstream stream(p);
41     stream << 3.25;
42   }
43   {
44     std::ifstream stream(p);
45     double x = 0;
46     stream >> x;
47     assert(x == 3.25);
48   }
49   {
50     std::ifstream stream(p, std::ios_base::out);
51     double x = 0;
52     stream >> x;
53     assert(x == 3.25);
54   }
55   std::remove(p.string().c_str());
56 
57 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
58   {
59     std::wofstream stream(p);
60     stream << 3.25;
61   }
62   {
63     std::wifstream stream(p);
64     double x = 0;
65     stream >> x;
66     assert(x == 3.25);
67   }
68   {
69     std::wifstream stream(p, std::ios_base::out);
70     double x = 0;
71     stream >> x;
72     assert(x == 3.25);
73   }
74   std::remove(p.string().c_str());
75 #endif
76 
77   return 0;
78 }
79