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

매개 변수

  • _Filename
    열려는 파일의 이름입니다.

  • _Mode
    하나에 열거형의 ios_base::openmode.

  • _Prot
    기본 파일 열기 보호 하는 shflag 매개 변수에서 _fsopen, _wfsopen.

설명

첫 번째 생성자를 호출 하 여 기본 클래스를 초기화 basic_istream(sb), 여기서 sb 저장 된 개체 클래스의 basic_filebuf<Elem, Tr>.It also initializes sb by calling basic_filebuf<Elem, Tr>.

두 번째 및 세 번째 생성자를 호출 하 여 기본 클래스를 초기화 basic_istream(sb).또한 초기화 sb 를 호출 하 여 basic_filebuf<Elem, Tr>, 다음 sb.open(_Filename,_Mode | ios_base::in).두 번째 함수 null 포인터를 반환 하는 경우 생성자를 호출 합니다. setstate(failbit).

네 번째 생성자 개체의 내용으로 초기화 right, 참조에 rvalue를 처리 합니다.

예제

다음 예제에서는 텍스트 파일에서에서 읽는 방법을 보여 줍니다.파일을 만들 수 있는 예제를 참조 하십시오. 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 프로그래밍

iostreams 규칙