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