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>

Elem

The basic element of the file buffer.

Tr

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();
        ifs.close();
    }
}

This is the contents of basic_ifstream_class.txt.

This is the contents of basic_ifstream_class.txt.

basic_ifstream

Initializes a new instance of a basic_ifstream object.

close

Closes a file.

is_open

Determines if a file is open.

open

Opens a file.

rdbuf

Returns the address of the stored stream buffer.

swap

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

operator=

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

Show:
© 2015 Microsoft