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