📄 filebuf_.gml
字号:
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='is_open'.int filebuf::is_open();
:eSNPL.
:SMTICS.
The &fn. queries the &obj. state.
:RSLTS.
The &fn. returns a non-zero value if the &obj.
is currently connected to a file. Otherwise, zero is returned.
:SALSO.
:SAL typ='mfun'.attach
:SAL typ='mfun'.close
:SAL typ='mfun'.fd
:SAL typ='mfun'.open
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.open
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='open'.filebuf *filebuf::open( const char *name,
:SNPFLF . ios::openmode mode,
:SNPFLF . int prot = filebuf::openprot );
:eSNPL.
:SMTICS.
The &fn. is used to connect the &obj. to a file specified by the
:ARG.name
parameter.
The file is opened using the specified
:ARG.mode
:PERIOD.
For details about the
:ARG.mode
parameter, see the description of
:MONO.ios::openmode
:PERIOD.
The
:ARG.prot
parameter specifies the file protection
attributes to use when creating a file.
:RSLTS.
The &fn. returns a pointer to the &obj. on success, otherwise &null. is
returned.
:SALSO.
:SAL typ='ctor'.
:SAL typ='mfun'.close
:SAL typ='mfun'.is_open
:SAL typ='mdata'.openprot
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mdata' prot='public'.openprot
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPD index='openprot'.static int const filebuf::openprot;
:eSNPL.
:SMTICS.
The &fn. is used to specify the default file protection to be used when
creating new files. This value is used as the default if no user specified
value is provided.
:P.
The default value is octal 0644. This is generally interpreted as follows:
:UL.
:LI.Owner: read/write
:LI.Group: read
:LI.World: read
:eUL.
:P.
Note that not all operating systems support all bits.
:SALSO.
:SAL typ='ctor'.
:SAL typ='mfun'.open
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public virtual'.overflow
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='overflow'.virtual int filebuf::overflow( int ch = EOF );
:eSNPL.
:SMTICS.
The &fn. provides the output communication to the file to which the &obj.
is connected. Member functions in the
:MONO.streambuf
class call the &fn. for the derived class when the &putarea. is full.
:INCLUDE file='fs_ovflw'.
:SALSO.
:SAL typ='ofun' ocls='streambuf'.overflow
:SAL typ='mfun'.underflow
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public virtual'.pbackfail
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='pbackfail'.virtual int filebuf::pbackfail( int ch );
:eSNPL.
:SMTICS.
The &fn. handles an attempt to put back a character when there is no room at
the beginning of the &getarea.:PERIOD.
The &fn. first calls the
:MONO.sync
virtual member function to flush the &putarea. and then it attempts to
seek backwards over
:ARG.ch
in the associated file.
:RSLTS.
The &fn. returns
:ARG.ch
on success, otherwise &eof. is returned.
:SALSO.
:SAL typ='ofun' ocls='streambuf'.pbackfail
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public virtual'.seekoff
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='seekoff'.virtual streampos filebuf::seekoff( streamoff offset,
:SNPFLF . ios::seekdir dir,
:SNPFLF . ios::openmode mode );
:eSNPL.
:SMTICS.
The &fn. is used to position the &obj. (and hence the file) to a particular
offset so that subsequent input or output operations commence from
that point.
The offset is specified by the
:ARG.offset
and
:ARG.dir
parameters.
:P.
Since the &getarea. and &putarea. pointers are tied together for
the &obj., the
:ARG.mode
parameter is ignored.
:P.
Before the actual seek occurs, the &getarea. and &putarea. of the &obj.
are flushed via the
:MONO.sync
virtual member function.
Then, the new position in the file is calculated and the seek takes place.
:INCLUDE file='seekdir'.
:RSLTS.
The &fn. returns the new position in the file on success, otherwise &eof. is
returned.
:SALSO.
:SAL typ='ofun' ocls='streambuf'.seekoff
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public virtual'.setbuf
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='setbuf'.virtual streambuf *filebuf::setbuf( char *buf, int len );
:eSNPL.
:SMTICS.
The &fn. is used to offer a buffer, specified by
:ARG.buf
and
:ARG.len
to the &obj.:PERIOD.
If the
:ARG.buf
parameter is &null. or the
:ARG.len
is less than or equal to zero, the request is to make the &obj.
unbuffered.
:P.
If the &obj. is already connected to a file and has a buffer, the offer is
rejected. In other words, a call to the &fn. after the &obj. has started to
be used usually fails because the &obj. has set up a buffer.
:P.
If the request is to make the &obj. unbuffered, the offer succeeds.
:P.
If the
:ARG.buf
is too small (less than five characters), the offer is rejected.
Five characters are required to support the default putback area.
:P.
Otherwise, the
:ARG.buf
is acceptable and the offer succeeds.
:P.
If the offer succeeds, the
:MONO.streambuf::setb
member function is called to set up the pointers to the buffer.
The
:MONO.streambuf::setb
member function releases the old buffer (if present),
depending on how that buffer was allocated.
:P.
Calls to the &fn. are usually made by a class derived from the
:MONO.fstream
class, not directly by a user program.
:RSLTS.
The &fn. returns a pointer to the &obj. on success, otherwise &null. is
returned.
:SALSO.
:SAL typ='ofun' ocls='streambuf'.setbuf
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public virtual'.sync
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='sync'.virtual int filebuf::sync();
:eSNPL.
:SMTICS.
The &fn. synchronizes the &obj. with the external file or device.
If the &putarea. contains characters it is flushed. This leaves the file
positioned after the last written character. If the &getarea.
contains buffered (unread) characters, file is
backed up to be positioned after the last read character.
:P.
Note that the &getarea. and &putarea. never both contain characters.
:RSLTS.
The &fn. returns ¬eof. on success, otherwise &eof. is returned.
:SALSO.
:SAL typ='ofun' ocls='streambuf'.sync
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public virtual'.underflow
:SNPL.
:SNPFLF .#include <fstream.h>
:SNPFLF .public:
:SNPF index='underflow'.virtual int filebuf::underflow();
:eSNPL.
:SMTICS.
The &fn. provides the input communication from the file to which the &obj.
is connected. Member functions in the
:MONO.streambuf
class call the &fn. for the derived class when the &getarea. is empty.
:INCLUDE file='fs_unflw'.
:SALSO.
:SAL typ='ofun' ocls='streambuf'.underflow
:SAL typ='mfun'.overflow
:eSALSO.
:eLIBF.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -