std::basic_ifstream<CharT,Traits>::basic_ifstream
Min standard notice:
Constructs new file stream.
# Declarations
basic_ifstream();
explicit basic_ifstream( const char* filename,
std::ios_base::openmode mode
= std::ios_base::in );
explicit basic_ifstream( const std::filesystem::path::value_type* filename,
std::ios_base::openmode mode
= std::ios_base::in );
(since C++17)
explicit basic_ifstream( const std::string& filename,
std::ios_base::openmode mode
= std::ios_base::in );
(since C++11)
template< class FsPath >
explicit basic_ifstream( const FsPath& filename,
std::ios_base::openmode mode
= std::ios_base::in );
(since C++17)
basic_ifstream( basic_ifstream&& other );
(since C++11)
basic_ifstream( const basic_ifstream& rhs ) = delete;
(since C++11)
# Parameters
filename: the name of the file to be openedmode: specifies stream open mode. Following constants and bit-wise OR between them may be used: Constant Explanation app seek to the end of stream before each write binary open in binary mode in open for reading out open for writing trunc discard the contents of the stream when opening ate seek to the end of stream immediately after open noreplace (C++23) open in exclusive modeother: another file stream to use as source
# Example
#include <fstream>
#include <string>
#include <utility>
int main()
{
std::ifstream f0;
std::ifstream f1("test.bin", std::ios::binary);
std::string name = "example.txt";
std::ifstream f2(name);
std::ifstream f3(std::move(f1));
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3430 | C++17 | std::filesystem::path overload led to unwanted conversions | avoided by making it a template |