56 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// FILE_DEPENDENCIES: test.dat12 13// <fstream>14 15// template <class charT, class traits = char_traits<charT> >16// class basic_ifstream17 18// void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in);19 20#include <fstream>21#include <filesystem>22#include <cassert>23 24#include "test_macros.h"25 26int main(int, char**) {27 {28 std::ifstream fs;29 assert(!fs.is_open());30 char c = 'a';31 fs >> c;32 assert(fs.fail());33 assert(c == 'a');34 fs.open(std::filesystem::path("test.dat"));35 assert(fs.is_open());36 fs >> c;37 assert(c == 'r');38 }39#ifndef TEST_HAS_NO_WIDE_CHARACTERS40 {41 std::wifstream fs;42 assert(!fs.is_open());43 wchar_t c = L'a';44 fs >> c;45 assert(fs.fail());46 assert(c == L'a');47 fs.open(std::filesystem::path("test.dat"));48 assert(fs.is_open());49 fs >> c;50 assert(c == L'r');51 }52#endif53 54 return 0;55}56