다음을 통해 공유


basic_filebuf Class

설명 형식 요소의 전송을 제어 하는 스트림 버퍼 Elem, 해당 문자 특성 클래스에 의해 결정 됩니다 Tr하 고 시퀀스의 요소를 외부 파일에 저장 합니다.

template <class Elem, class Tr = char_traits<Elem> >
    class basic_filebuf : public basic_streambuf<Elem, Tr>

매개 변수

  • Elem
    파일 버퍼의 기본 요소입니다.

  • Tr
    특성에는 파일 버퍼의 기본 요소 (일반적으로 char_traits<Elem>).

설명

템플릿 클래스 형식 요소의 전송을 제어 하는 스트림 버퍼를 설명 Elem, 해당 문자 특성 클래스에 의해 결정 됩니다 Tr하 고 시퀀스의 요소를 외부 파일에 저장 합니다.

[!참고]

개체 형식의 basic_filebuf 가진 형식의 내부 버퍼가 만들어집니다 char * 관계 없이 char_type 형식 매개 변수에서 지정한 Elem.즉 유니코드 문자열 (포함 된 wchar_t 문자)을 ANSI 문자열로 변환 됩니다 (포함 된 char 문자) 내부 버퍼에 쓰기 전에.새 버퍼 유형의 버퍼에 유니코드 문자열을 저장 하려면 만들기 wchar_t 를 사용 하 여 설정 하 고 있는 basic_streambuf::pubsetbuf() 메서드.이 동작을 보여 주는 예제를 보려면 아래를 참조 하십시오.

An object of class basic_filebuf<Elem, Tr> 지정 된 파일 포인터를 저장의 FILE 열려 있는 파일에 연결 된 스트림을 제어 하는 개체입니다.두 파일 변환 패싯 사용에 대 한 포인터는 보호 된 멤버 함수에 의해 저장 오버플로언더플로.자세한 내용은 basic_filebuf::open를 참조하십시오.

예제

다음 예제에서는 형식의 개체를 강제로 basic_filebuf<wchar_t> 호출 하 여 내부 버퍼에 유니코드 문자를 저장 하는 pubsetbuf() 메서드.

// unicode_basic_filebuf.cpp
// compile with: /EHsc

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <memory.h>
#include <string.h>

#define IBUFSIZE 16

using namespace std;

void hexdump(const string& filename);

int main()
{
    wchar_t* wszHello = L"Hello World";
    wchar_t wBuffer[128];

    basic_filebuf<wchar_t> wOutFile;

    // Open a file, wcHello.txt, then write to it, then dump the
    // file's contents in hex
    wOutFile.open("wcHello.txt",
        ios_base::out | ios_base::trunc | ios_base::binary);
    if(!wOutFile.is_open())
    {
        cout << "Error Opening wcHello.txt\n";
        return -1;
    }
    wOutFile.sputn(wszHello, (streamsize)wcslen(wszHello));
    wOutFile.close();
    cout << "Hex Dump of wcHello.txt - note that output is ANSI chars:\n";
    hexdump(string("wcHello.txt"));

    // Open a file, wwHello.txt, then set the internal buffer of
    // the basic_filebuf object to be of type wchar_t, then write
    // to the file and dump the file's contents in hex
    wOutFile.open("wwHello.txt",
        ios_base::out | ios_base::trunc | ios_base::binary);
    if(!wOutFile.is_open())
    {
        cout << "Error Opening wwHello.txt\n";
        return -1;
    }
    wOutFile.pubsetbuf(wBuffer, (streamsize)128);
    wOutFile.sputn(wszHello, (streamsize)wcslen(wszHello));
    wOutFile.close();
    cout << "\nHex Dump of wwHello.txt - note that output is wchar_t chars:\n";
    hexdump(string("wwHello.txt"));

    return 0;
}

// dump contents of filename to stdout in hex
void hexdump(const string& filename)
{
    fstream ifile(filename.c_str(),
        ios_base::in | ios_base::binary);
    char *ibuff = new char[IBUFSIZE];
    char *obuff = new char[(IBUFSIZE*2)+1];
    int i;

    if(!ifile.is_open())
    {
        cout << "Cannot Open " << filename.c_str()
             << " for reading\n";
        return;
    }
    if(!ibuff || !obuff)
    {
        cout << "Cannot Allocate buffers\n";
        ifile.close();
        return;
    }

    while(!ifile.eof())
    {
        memset(obuff,0,(IBUFSIZE*2)+1);
        memset(ibuff,0,IBUFSIZE);
        ifile.read(ibuff,IBUFSIZE);

        // corner case where file is exactly a multiple of
        // 16 bytes in length
        if(ibuff[0] == 0 && ifile.eof())
            break;

        for(i = 0; i < IBUFSIZE; i++)
        {
            if(ibuff[i] >= ' ')
                obuff[i] = ibuff[i];
            else
                obuff[i] = '.';

            cout << setfill('0') << setw(2) << hex
                 << (int)ibuff[i] << ' ';
        }
        cout << "  " << obuff << endl;
    }
    ifile.close();
}
  
  
  
  

tzf8k3z8.collapse_all(ko-kr,VS.110).gif생성자

basic_filebuf

개체 형식의 생성 basic_filebuf.

tzf8k3z8.collapse_all(ko-kr,VS.110).gif형식 정의

char_type

형식 이름에 연결의 Elem 템플릿 매개 변수가 있습니다.

int_type

내에서 변경할 수 있습니다 basic_filebuf의 형식에 같은 이름에 해당 하는 범위는 Tr 범위.

off_type

내에서 변경할 수 있습니다 basic_filebuf의 형식에 같은 이름에 해당 하는 범위는 Tr 범위.

pos_type

내에서 변경할 수 있습니다 basic_filebuf의 형식에 같은 이름에 해당 하는 범위는 Tr 범위.

traits_type

형식 이름에 연결의 Tr 템플릿 매개 변수가 있습니다.

tzf8k3z8.collapse_all(ko-kr,VS.110).gif멤버 함수

닫기

파일을 닫습니다.

is_open

파일이 열려 있는지 여부를 나타냅니다.

열기

파일을 엽니다.

오버플로(overflow)

새 문자를 전체 버퍼에 삽입 될 때 호출할 수 있는 보호 된 가상 함수입니다.

pbackfail

보호 된 가상 멤버 함수 요소 입력된 스트림으로 놔 하 고 현재 요소 (다음 포인터가 가리키는) 쉽게 하려고 합니다.

seekoff

보호 된 가상 멤버 함수는 제어 된 스트림의 현재 위치를 변경 하려고 합니다.

seekpos

보호 된 가상 멤버 함수는 제어 된 스트림의 현재 위치를 변경 하려고 합니다.

setbuf

각 파생된 스트림 버퍼는 작업이 특정 보호 된 가상 멤버 함수를 수행합니다.

스왑

이 콘텐츠를 교환 basic_filebuf 제공 된 내용에 대 한 basic_filebuf 매개 변수.

동기화

보호 된 가상 함수를 모든 관련된 외부 스트림과 제어 스트림 동기화 하려고 합니다.

uflow

보호는 입력된 스트림에서 현재 요소를 추출 하는 가상 함수입니다.

언더플로

보호는 입력된 스트림에서 현재 요소를 추출 하는 가상 함수입니다.

요구 사항

헤더: <fstream>

네임 스페이스: std

참고 항목

참조

표준 C++ 라이브러리에서 스레드로부터의 안전성

iostream 프로그래밍

iostreams 규칙

기타 리소스

<fstream> 멤버

basic_filebuf 멤버