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