📄 filebuf_.gml
字号:
:P.
The input/output stream classes provide program access to the file system.
In addition, various options for formatting of output and reading of
input are provided.
.*
:CLFNM.filebuf
:CMT.========================================================================
:LIBF fmt='hdr'.filebuf
:HFILE.fstream.h
:DVFML.
:DVFM.streambuf
:eDVFML.
:CLSS.
The &cls. is derived from the
:MONO.streambuf
class, and provides additional functionality required
to communicate with external files.
Seek operations are supported when the underlying file supports seeking.
Both input and output operations may be performed using a &obj.,
again when the underlying file supports read/write access.
:P.
&obj.s are buffered by default, so the &rsvarea. is allocated automatically
unless one is specified when the &obj. is created.
The &getarea. and &putarea. pointers operate as if they were tied together.
There is only one current position in a &obj.:PERIOD.
:INCLUDE file='flb_desc'.
:P.
C++ programmers who wish to use files without deriving new objects
do not need to explicitly create or use a &obj.:PERIOD.
:HDG.Public Data Members
The following data member is declared in the public interface.
Its value is the default file protection that is used when
creating new files. It is primarily referenced as a default
argument in member functions.
:MFNL.
:MFN index='openprot'.static int const openprot;
:eMFNL.
:HDG.Public Member Functions
The following member functions are declared in the public interface:
:MFNL.
:MFCD cd_idx='c'.filebuf();
:MFCD cd_idx='c'.filebuf( filedesc );
:MFCD cd_idx='c'.filebuf( filedesc, char *, int );
:MFCD cd_idx='d' .~~filebuf();
:MFN index='is_open' .int is_open() const;
:MFN index='fd' .filedesc fd() const;
:MFN index='attach' .filebuf *attach( filedesc );
:MFN index='open' .filebuf *open( char const *,
:MFNFLF . ios::openmode,
:MFNFLF . int = filebuf::openprot );
:MFN index='close' .filebuf *close();
:MFN index='pbackfail'.virtual int pbackfail( int );
:MFN index='overflow' .virtual int overflow( int = EOF );
:MFN index='underflow'.virtual int underflow();
:MFN index='setbuf' .virtual streambuf *setbuf( char *, int );
:MFN index='seekoff' .virtual streampos seekoff( streamoff,
:MFNFLF . ios::seekdir,
:MFNFLF . ios::openmode );
:MFN index='sync' .virtual int sync();
:eMFNL.
:eCLSS.
:SALSO.
:SAL typ='cls'.fstreambase
:SAL typ='cls'.streambuf
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.attach
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='attach'.filebuf *filebuf::attach( filedesc hdl );
:eSNPL.
:SMTICS.
The &fn. connects an existing &obj. to an open file via the file's descriptor
or handle specified by
:ARG.hdl
:PERIOD.
If the &obj. is already connected to a file, the &fn. fails. Otherwise,
the &fn. extracts information from the file system to determine the
capabilities of the file and hence the &obj.:PERIOD.
:RSLTS.
The &fn. returns a pointer to the &obj. on success, otherwise &null. is
returned.
:SALSO.
:SAL typ='ctor'.
:SAL typ='mfun'.fd
:SAL typ='mfun'.open
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.close
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='close'.filebuf *filebuf::close();
:eSNPL.
:SMTICS.
The &fn. disconnects the &obj. from a connected file and closes the file.
Any buffered output is flushed before the file is closed.
:RSLTS.
The &fn. returns a pointer to the &obj. on success, otherwise &null. is
returned.
:SALSO.
:SAL typ='ctor'.
:SAL typ='mfun'.fd
:SAL typ='mfun'.is_open
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.fd
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='fd'.filedesc filebuf::fd() const;
:eSNPL.
:SMTICS.
The &fn. queries the state of the &obj. file handle.
:RSLTS.
The &fn. returns the file descriptor or handle of the file to which the &obj.
is currently connected. If the &obj. is not currently connected to a file,
&eof. is returned.
:SALSO.
:SAL typ='mfun'.attach
:SAL typ='mfun'.is_open
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='ctor' prot='public'.filebuf
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPCD cd_idx='c'.filebuf::filebuf();
:eSNPL.
:SMTICS.
This form of the &fn. creates a &obj. that is not currently
connected to any file. A call to the
:MONO.fd
member function for this created &obj. returns &eof., unless a file
is connected using the
:MONO.attach
member function.
:RSLTS.
The &fn. produces a &obj. that is not currently connected to any file.
:SALSO.
:SAL typ='dtor'.
:SAL typ='mfun'.attach
:SAL typ='mfun'.open
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='ctor' prot='public'.filebuf
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPCD cd_idx='c'.filebuf::filebuf( filedesc hdl );
:eSNPL.
:SMTICS.
This form of the &fn. creates a &obj. that is connected to an open file.
The file is specified via the
:ARG.hdl
parameter, which is a file descriptor or handle.
:P.
This form of the &fn. is similar to using the default
constructor, and calling the
:MONO.attach
member function. A call to the
:MONO.fd
member function for this created &obj. returns
:ARG.hdl
:PERIOD.
:RSLTS.
The &fn. produces a &obj. that is connected to
:ARG.hdl
:PERIOD.
:SALSO.
:SAL typ='dtor'.
:SAL typ='mfun'.attach
:SAL typ='mfun'.open
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='ctor' prot='public'.filebuf
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPCD cd_idx='c'.filebuf::filebuf( filedesc hdl, char *buf, int len );
:eSNPL.
:SMTICS.
This form of the &fn. creates a &obj. that is
connected to an open file and that uses the buffer specified by
:ARG.buf
and
:ARG.len
:PERIOD.
The file is specified via the
:ARG.hdl
parameter, which is a file descriptor or handle. If
:ARG.buf
is &null. and/or
:ARG.len
is less than or equal to zero, the &obj. is unbuffered,
so that reading and/or writing take place one character at a time.
:P.
This form of the &fn. is similar to using the default constructor, and
calling the
:MONO.attach
and
:MONO.setbuf
member functions.
:RSLTS.
The &fn. constructor produces a &obj. that is connected to
:ARG.hdl
:PERIOD.
:SALSO.
:SAL typ='dtor'.
:SAL typ='mfun'.attach
:SAL typ='mfun'.open
:SAL typ='mfun'.setbuf
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='dtor' prot='public'.~~filebuf
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPCD cd_idx='d'.filebuf::~~filebuf();
:eSNPL.
:SMTICS.
The &fn.
closes the file if it was explicitly opened using the
:MONO.open
member function. Otherwise, the destructor takes no explicit action.
The
:MONO.streambuf
destructor is called to destroy that portion of the &obj.:PERIOD.
The call to the &fn. is inserted implicitly by the compiler
at the point where the &obj. goes out of scope.
:RSLTS.
The &obj. is destroyed.
:SALSO.
:SAL typ='dtor'.
:SAL typ='mfun'.close
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.is_open
:SNPL.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -