xref: /llvm-project/libcxx/test/std/input.output/file.streams/fstreams/ifstream.cons/pointer.pass.cpp (revision b9a2658a3e8bd13b0f9e7a8a440832a95b377216)
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // FILE_DEPENDENCIES: test.dat
10 
11 // XFAIL: FROZEN-CXX03-HEADERS-FIXME
12 
13 // <fstream>
14 
15 // template <class charT, class traits = char_traits<charT> >
16 // class basic_ifstream
17 
18 // explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in);
19 
20 #include <fstream>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 #include "operator_hijacker.h"
25 
26 int main(int, char**)
27 {
28     {
29         std::ifstream fs("test.dat");
30         double x = 0;
31         fs >> x;
32         assert(x == 3.25);
33     }
34     {
35       std::basic_ifstream<char, operator_hijacker_char_traits<char> > fs("test.dat");
36       std::basic_string<char, operator_hijacker_char_traits<char> > x;
37       fs >> x;
38       assert(x == "3.25");
39     }
40     // std::ifstream(const char*, std::ios_base::openmode) is tested in
41     // test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
42     // which creates writable files.
43 
44 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
45     {
46         std::wifstream fs("test.dat");
47         double x = 0;
48         fs >> x;
49         assert(x == 3.25);
50     }
51     {
52       std::basic_ifstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fs("test.dat");
53       std::basic_string<wchar_t, operator_hijacker_char_traits<wchar_t> > x;
54       fs >> x;
55       assert(x == L"3.25");
56     }
57     // std::wifstream(const char*, std::ios_base::openmode) is tested in
58     // test/std/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp
59     // which creates writable files.
60 #endif
61 
62   return 0;
63 }
64