basic_ifstream::basic_ifstream

构造对象类型 basic_ifstream

basic_ifstream( );
explicit basic_ifstream(
    const char *_Filename,
    ios_base::openmode _Mode = ios_base::in,
    int _Prot = (int)ios_base::_Openprot
);
explicit basic_ifstream(
    const wchar_t *_Filename,
    ios_base::openmode _Mode = ios_base::in,
    int _Prot = (int)ios_base::_Openprot
);
basic_ifstream(basic_ifstream&& right);

参数

备注

第一个构造函数通过调用 basic_istream(sb),其中 sb 是选件类 basic_filebuf<Elem,Tr> 中的对象。它还通过调用 basic_filebuf<Elem 初始化 sb,Tr>。

第二个和第三个构造函数通过调用 basic_istream初始化基类(sb)。它还通过调用basic_filebuf<Elem 初始化 sb,Tr>,然后 sb.open(_Filename,_Mode |ios_base::in).如果后一个函数返回null指针,构造函数调用 setstate(failbit)。

rvalue引用,第四个构造函数初始化。right内容的对象,将。

示例

下面的示例演示如何写入文本从文件。若要创建文件,对于 basic_ofstream::basic_ofstream请参见示例。

// basic_ifstream_ctor.cpp
// compile with: /EHsc

#include <fstream>
#include <iostream>

using namespace std;

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

输入:basic_ifstream_ctor.txt

This is the contents of basic_ifstream_ctor.txt.

Output

This is the contents of basic_ifstream_ctor.txt.

要求

标头: <fstream>

命名空间: std

请参见

参考

basic_ifstream Class

iostream编程

(mfc)约定