xref: /llvm-project/libcxx/test/std/input.output/file.streams/fstreams/fstream.members/open_path.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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 
11 // <fstream>
12 
13 // plate <class charT, class traits = char_traits<charT> >
14 // class basic_fstream
15 
16 // void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in|ios_base::out);
17 
18 #include <fstream>
19 #include <filesystem>
20 #include <cassert>
21 #include "platform_support.h"
22 
23 int main() {
24   std::filesystem::path p = get_temp_file_name();
25   {
26     std::fstream stream;
27     assert(!stream.is_open());
28     stream.open(p,
29                 std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
30     assert(stream.is_open());
31     double x = 0;
32     stream << 3.25;
33     stream.seekg(0);
34     stream >> x;
35     assert(x == 3.25);
36   }
37   std::remove(p.c_str());
38   {
39     std::wfstream stream;
40     assert(!stream.is_open());
41     stream.open(p,
42                 std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
43     assert(stream.is_open());
44     double x = 0;
45     stream << 3.25;
46     stream.seekg(0);
47     stream >> x;
48     assert(x == 3.25);
49   }
50   std::remove(p.c_str());
51 }
52