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.

For a list of all members of this type, see basic_ifstream Members.

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

Parameters

  • Elem
    The basic element of the file buffer.

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

Remarks

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

Example

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

Input: basic_ifstream_class.txt

This is the contents of basic_ifstream_class.txt.

Output

This is the contents of basic_ifstream_class.txt.

Requirements

Header: <fstream>

Namespace: std

See Also

Reference

Thread Safety in the Standard C++ Library

iostream Programming

iostreams Conventions

Other Resources

<fstream> Members

basic_ifstream Members