Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

basic_filebuf

Library:  Input/output


basic_filebuf basic_streambuf

Local Index

Members

Non-Members

Summary

Class that associates the input or output sequence with a file

Synopsis

#include <fstream> 

namespace std {
  template<class charT, class traits = char_traits<charT> >
  class basic_filebuf;
}

Description

The class template basic_filebuf is derived from basic_streambuf. It associates the input or output sequence with a file. Each object of type basic_filebuf controls two character sequences:

The restrictions on reading and writing a sequence controlled by an object of class basic_filebuf are the same as for reading and writing with the Standard C library files.

If the file is not open for reading, the input sequence cannot be read. If the file is not open for writing, the output sequence cannot be written. A joint file position is maintained for both the input and output sequences.

A file has byte sequences, so the basic_filebuf class treats a file as the external source (or sink) byte sequence. In order to provide the contents of a file as wide character sequences, a wide-oriented file buffer called wfilebuf converts wide character sequences to multibyte character sequences (and vice versa) according to the current locale being used in the stream buffer.

Interface

Member Types

char_type
int_type
off_type
pos_type
traits_type

Nonmember Types

filebuf
wfilebuf 

Constructors

basic_filebuf();
basic_filebuf(int fd, char_type *buf = 0, 
              streamsize n = /* default size */);

NOTE -- This function is not part of the C++ Standard, but is included here as an extension to manipulate pipes, sockets, or other UNIX devices that can be accessed through file descriptors. See Appendix B for a complete list of extensions of this implementation.
basic_filebuf(FILE *fp, char_type *buf = 0, 
              streamsize n = /* default size */);

NOTE -- This function is not part of the C++ Standard, but is included here as an extension. See Appendix B for a complete list of extensions of this implementation.

Destructors

virtual ~basic_filebuf();

Member Functions

basic_filebuf<charT, traits>*
attach(int fd);

NOTE -- This function is not part of the C++ Standard, but is provided as an extension of this implementation for compatibility with Classic Iostreams. See Appendix B for a complete list of extensions of this implementation.
int
fd() const;

NOTE -- This function is not part of the C++ Standard, but is provided as an extension of this implementation for compatibility with Classic Iostreams. See Appendix B for a complete list of extensions of this implementation.
basic_filebuf<charT,traits>* 
close();
int
detach(); 

NOTE -- This function is not part of the C++ Standard, but is provided as an extension of this implementation for compatibility with Classic Iostreams. See Appendix B for a complete list of extensions of this implementation.
bool 
is_open() const; 
basic_filebuf<charT,traits>* 
open(const char* fname, ios_base::openmode mode, 
     long protection = 0666); 

NOTE -- The behavior of the function when (fname == 0) evaluates to true is not required by the C++ Standard, but is provided as an extension of this implementation. See Appendix B for a complete list of extensions of this implementation.

NOTE -- The protection argument does not appear in the C++ Standard, but is included here as an extension. See Appendix B for a complete list of extensions of this implementation.
basic_filebuf<charT,traits>*
open(int fd, char_type *buf = 0, 
     streamsize n = /* default size */);

NOTE -- This function is not part of the C++ Standard, but is included here as an extension in order to manipulate pipes, sockets, or other UNIX devices that can be accessed through file descriptors. See Appendix B for a complete list of extensions of this implementation.
basic_filebuf<charT,traits>*
open(FILE *fp, char_type *buf = 0, 
     streamsize n = /* default size */);

NOTE -- This function is not part of the C++ Standard, but is provided as a convenience extension. See Appendix B for a complete list of extensions of this implementation.
int_type 
overflow(int_type c = traits_type::eof()); 
int_type 
pbackfail(int_type c = traits_type::eof()); 
pos_type 
seekoff(off_type off, ios_base::seekdir way,
        ios_base::openmode which = ios_base::in |
        ios_base::out); 

File buffers that use the locale::codecvt facet, and perform state dependent conversion, support seeking only to the beginning of the file, to the current position, or to a position previously obtained by a call to one of the iostreams seeking functions.

pos_type 
seekpos(pos_type sp,ios_base::openmode  
          which = ios_base::in | ios_base::out); 
basic_filebuf<charT,traits>* 
setbuf(char_type *s, streamsize n); 
int 
sync();
int_type 
underflow();
streamsize 
xsputn(const char_type* s, streamsize n); 

Example

See Also

char_traits, ios_base, basic_ios, basic_streambuf, basic_ifstream, basic_ofstream, basic_fstream

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, Section 27.8.1.1



Previous fileTop of DocumentContentsIndex pageNext file