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