다음을 통해 공유


basic_ifstream 클래스

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

Input: basic_ifstream_class.txt

This is the contents of basic_ifstream_class.txt.

Output

This is the contents of basic_ifstream_class.txt.

생성자

basic_ifstream

basic_ifstream 개체의 새 인스턴스를 초기화합니다.

멤버 함수

close

Closes a file.

is_open

Determines if a file is open.

open

파일을 엽니다.

rdbuf

Returns the address of the stored stream buffer.

스왑

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>

네임스페이스: std

참고 항목

참조

C++ 표준 라이브러리의 스레드 보안

iostream 프로그래밍

iostreams 규칙

기타 리소스

<fstream> 멤버

basic_ifstream 멤버