다음을 통해 공유


basic_fstream 클래스

Describes an object that controls insertion and extraction of elements and encoded objects using 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_fstream : public basic_iostream<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 get pointer and put pointer of an fstream object are NOT independent of each other.If the get pointer moves, so does the put pointer.

예제

The following example demonstrates how to create a basic_fstream object that can be read from and written to.

// basic_fstream_class.cpp
// compile with: /EHsc

#include <fstream>
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
    fstream fs("fstream.txt", ios::in | ios::out | ios::trunc);
    if (!fs.bad())
    {
        // Write to the file.
        fs << "Writing to a basic_fstream object..." << endl;
        fs.close();

        // Dump the contents of the file to cout.
        fs.open("fstream.txt", ios::in);
        cout << fs.rdbuf();
        fs.close();
    }
}
  

생성자

basic_fstream

'basic_fstream' 형식의 개체를 생성합니다.

멤버 함수

close

Closes a file.

is_open

Determines if a file is open.

open

파일을 엽니다.

rdbuf

Returns the address of the stored stream buffer, of type pointer to basic_filebuf<Elem, Tr>.

스왑

Exchanges the content of this object with the content of another basic_fstream object.

요구 사항

Header: <fstream>

네임스페이스: std

참고 항목

참조

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

iostream 프로그래밍

iostreams 규칙

기타 리소스

<fstream> 멤버

basic_fstream 멤버