62 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// explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in);17 18#include <fstream>19#include <cassert>20 21#include "test_macros.h"22#include "operator_hijacker.h"23 24int main(int, char**)25{26 {27 std::ifstream fs(std::string("test.dat"));28 double x = 0;29 fs >> x;30 assert(x == 3.25);31 }32 {33 std::basic_ifstream<char, operator_hijacker_char_traits<char> > fs(std::string("test.dat"));34 std::basic_string<char, operator_hijacker_char_traits<char> > x;35 fs >> x;36 assert(x == "3.25");37 }38 // std::ifstream(const std::string&, std::ios_base::openmode) is tested in39 // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp40 // which creates writable files.41 42#ifndef TEST_HAS_NO_WIDE_CHARACTERS43 {44 std::wifstream fs(std::string("test.dat"));45 double x = 0;46 fs >> x;47 assert(x == 3.25);48 }49 {50 std::basic_ifstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fs(std::string("test.dat"));51 std::basic_string<wchar_t, operator_hijacker_char_traits<wchar_t> > x;52 fs >> x;53 assert(x == L"3.25");54 }55 // std::wifstream(const std::string&, std::ios_base::openmode) is tested in56 // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp57 // which creates writable files.58#endif59 60 return 0;61}62