• 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_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 
main()27 int main() {
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