brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · ef15ac3 Raw
68 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <fstream>12 13// plate <class charT, class traits = char_traits<charT> >14// class basic_ofstream15 16// void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out);17 18#include <fstream>19#include <filesystem>20#include <cassert>21#include "test_macros.h"22#include "platform_support.h"23 24namespace fs = std::filesystem;25 26int main(int, char**) {27  fs::path p = get_temp_file_name();28  {29    std::ofstream fs;30    assert(!fs.is_open());31    char c = 'a';32    fs << c;33    assert(fs.fail());34    fs.open(p);35    assert(fs.is_open());36    fs << c;37  }38  {39    std::ifstream fs(p.c_str());40    char c = 0;41    fs >> c;42    assert(c == 'a');43  }44  std::remove(p.string().c_str());45 46#ifndef TEST_HAS_NO_WIDE_CHARACTERS47  {48    std::wofstream fs;49    assert(!fs.is_open());50    wchar_t c = L'a';51    fs << c;52    assert(fs.fail());53    fs.open(p);54    assert(fs.is_open());55    fs << c;56  }57  {58    std::wifstream fs(p.c_str());59    wchar_t c = 0;60    fs >> c;61    assert(c == L'a');62  }63  std::remove(p.string().c_str());64#endif65 66  return 0;67}68