• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
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 "platform_support.h"
23 
24 namespace fs = std::filesystem;
25 
main()26 int main() {
27   fs::path p = get_temp_file_name();
28   {
29     static_assert(!std::is_convertible<fs::path, std::ofstream>::value,
30                   "ctor should be explicit");
31     static_assert(std::is_constructible<std::ofstream, fs::path const&,
32                                         std::ios_base::openmode>::value,
33                   "");
34   }
35   {
36     std::ofstream stream(p);
37     stream << 3.25;
38   }
39   {
40     std::ifstream stream(p);
41     double x = 0;
42     stream >> x;
43     assert(x == 3.25);
44   }
45   {
46     std::ifstream stream(p, std::ios_base::out);
47     double x = 0;
48     stream >> x;
49     assert(x == 3.25);
50   }
51   std::remove(p.c_str());
52   {
53     std::wofstream stream(p);
54     stream << 3.25;
55   }
56   {
57     std::wifstream stream(p);
58     double x = 0;
59     stream >> x;
60     assert(x == 3.25);
61   }
62   {
63     std::wifstream stream(p, std::ios_base::out);
64     double x = 0;
65     stream >> x;
66     assert(x == 3.25);
67   }
68   std::remove(p.c_str());
69 }
70