brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · ebd9909 Raw
54 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// FILE_DEPENDENCIES: test.dat10 11// <fstream>12 13// template <class charT, class traits = char_traits<charT> >14// class basic_ifstream15 16// void open(const char* s, ios_base::openmode mode = ios_base::in);17 18#include <fstream>19#include <cassert>20 21#include "test_macros.h"22 23int main(int, char**)24{25    {26        std::ifstream fs;27        assert(!fs.is_open());28        char c = 'a';29        fs >> c;30        assert(fs.fail());31        assert(c == 'a');32        fs.open("test.dat");33        assert(fs.is_open());34        fs >> c;35        assert(c == 'r');36    }37#ifndef TEST_HAS_NO_WIDE_CHARACTERS38    {39        std::wifstream fs;40        assert(!fs.is_open());41        wchar_t c = L'a';42        fs >> c;43        assert(fs.fail());44        assert(c == L'a');45        fs.open("test.dat");46        assert(fs.is_open());47        fs >> c;48        assert(c == L'r');49    }50#endif51 52  return 0;53}54