Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
basic_ifstream Class

basic_ifstream Class

Describes an object that controls extraction of elements and encoded objects from a stream buffer of class basic_filebuf<Elem, Tr>, with elements of type Elem, whose character traits are determined by the class Tr.

template <class Elem, class Tr = char_traits<Elem> >
    class basic_ifstream : public basic_istream<Elem, Tr>


The basic element of the file buffer.


The traits of the basic element of the file buffer (usually char_traits<Elem>).

The object stores an object of class basic_filebuf<Elem, Tr>.

The following example shows how to read in text from a file.

// basic_ifstream_class.cpp
// compile with: /EHsc

#include <fstream>
#include <iostream>

using namespace std;

int main(int argc, char **argv)
    ifstream ifs("basic_ifstream_class.txt");
    if (!ifs.bad())
        // Dump the contents of the file to cout.
        cout << ifs.rdbuf();

This is the contents of basic_ifstream_class.txt.

This is the contents of basic_ifstream_class.txt.


Initializes a new instance of a basic_ifstream object.


Closes a file.


Determines if a file is open.


Opens a file.


Returns the address of the stored stream buffer.


Exchanges the content of this basic_ifstream for the content of the provided basic_ifstream.


Assigns the content of this stream object. This is a move assignment involving an rvalue that does not leave a copy behind.

Header: <fstream>

Namespace: std

© 2015 Microsoft