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 // XFAIL: dylib-has-no-filesystem
11 
12 // <fstream>
13 
14 // plate <class charT, class traits = char_traits<charT> >
15 // class basic_fstream
16 
17 // explicit basic_fstream(const filesystem::path& s,
18 //     ios_base::openmode mode = ios_base::in|ios_base::out);
19 
20 #include <fstream>
21 #include <filesystem>
22 #include <cassert>
23 #include "platform_support.h"
24 
25 namespace fs = std::filesystem;
26 
27 int main(int, char**) {
28   fs::path p = get_temp_file_name();
29   {
30     std::fstream fs(p, std::ios_base::in | std::ios_base::out |
31                            std::ios_base::trunc);
32     double x = 0;
33     fs << 3.25;
34     fs.seekg(0);
35     fs >> x;
36     assert(x == 3.25);
37   }
38   std::remove(p.c_str());
39   {
40     std::wfstream fs(p, std::ios_base::in | std::ios_base::out |
41                             std::ios_base::trunc);
42     double x = 0;
43     fs << 3.25;
44     fs.seekg(0);
45     fs >> x;
46     assert(x == 3.25);
47   }
48   std::remove(p.c_str());
49 
50   return 0;
51 }
52