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: libcpp-has-no-filesystem-library 11 12 // Filesystem is supported on Apple platforms starting with macosx10.15. 13 // UNSUPPORTED: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}} 14 15 // <fstream> 16 17 // plate <class charT, class traits = char_traits<charT> > 18 // class basic_fstream 19 20 // explicit basic_fstream(const filesystem::path& s, 21 // ios_base::openmode mode = ios_base::in|ios_base::out); 22 23 #include <fstream> 24 #include <filesystem> 25 #include <cassert> 26 #include "test_macros.h" 27 #include "platform_support.h" 28 29 namespace fs = std::filesystem; 30 31 int main(int, char**) { 32 fs::path p = get_temp_file_name(); 33 { 34 std::fstream fs(p, std::ios_base::in | std::ios_base::out | 35 std::ios_base::trunc); 36 double x = 0; 37 fs << 3.25; 38 fs.seekg(0); 39 fs >> x; 40 assert(x == 3.25); 41 } 42 std::remove(p.string().c_str()); 43 44 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 45 { 46 std::wfstream fs(p, std::ios_base::in | std::ios_base::out | 47 std::ios_base::trunc); 48 double x = 0; 49 fs << 3.25; 50 fs.seekg(0); 51 fs >> x; 52 assert(x == 3.25); 53 } 54 std::remove(p.string().c_str()); 55 #endif 56 57 return 0; 58 } 59