• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // UNSUPPORTED: c++03, c++11, c++14
10 // UNSUPPORTED: c++filesystem-disabled
11 // FILE_DEPENDENCIES: test.dat
12 
13 // <fstream>
14 
15 // template <class charT, class traits = char_traits<charT> >
16 // class basic_ifstream
17 
18 // explicit basic_ifstream(const filesystem::path& s,
19 //     ios_base::openmode mode = ios_base::in);
20 
21 #include <fstream>
22 #include <filesystem>
23 #include <cassert>
24 
25 #include "test_macros.h"
26 
27 namespace fs = std::filesystem;
28 
main(int,char **)29 int main(int, char**) {
30   {
31     fs::path p;
32     static_assert(!std::is_convertible<fs::path, std::ifstream>::value,
33                   "ctor should be explicit");
34     static_assert(std::is_constructible<std::ifstream, fs::path const&,
35                                         std::ios_base::openmode>::value,
36                   "");
37   }
38   {
39     std::ifstream fs(fs::path("test.dat"));
40     double x = 0;
41     fs >> x;
42     assert(x == 3.25);
43   }
44   // std::ifstream(const fs::path&, std::ios_base::openmode) is tested in
45   // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
46   // which creates writable files.
47   {
48     std::wifstream fs(fs::path("test.dat"));
49     double x = 0;
50     fs >> x;
51     assert(x == 3.25);
52   }
53   // std::wifstream(const fs::path&, std::ios_base::openmode) is tested in
54   // test/std/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp
55   // which creates writable files.
56 
57   return 0;
58 }
59