libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

open_path.pass.cpp (1387B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: c++98, c++03, c++11, c++14
     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 "platform_support.h"
     23 
     24 int main() {
     25   std::filesystem::path p = get_temp_file_name();
     26   {
     27     std::fstream stream;
     28     assert(!stream.is_open());
     29     stream.open(p,
     30                 std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
     31     assert(stream.is_open());
     32     double x = 0;
     33     stream << 3.25;
     34     stream.seekg(0);
     35     stream >> x;
     36     assert(x == 3.25);
     37   }
     38   std::remove(p.c_str());
     39   {
     40     std::wfstream stream;
     41     assert(!stream.is_open());
     42     stream.open(p,
     43                 std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
     44     assert(stream.is_open());
     45     double x = 0;
     46     stream << 3.25;
     47     stream.seekg(0);
     48     stream >> x;
     49     assert(x == 3.25);
     50   }
     51   std::remove(p.c_str());
     52 }