1. C + + Each stream object maintains a buffer, which is essentially a character array for storing input and output sequences, and is described by three pointers (Begin_pointer,next_pointer,end_pointer), which are divided into full buffers by the refresh type. Row buffers and unbuffered. (see "C + + input and output stream and localization" for details)
2. Commonly used buffer functions
Function |
Role |
int Peek () |
Returns the next character in the buffer, and the pointer does not move back |
void get (char ch) |
Assigns the next character of the buffer to CH, and the pointer moves back |
Char get () |
The next character of the buffer is taken out and returned, and the pointer moves back |
void putback (char ch) |
Puts a function that was previously read from the stream back into the buffer and inserts it into the current pointer position |
IStream &ignore (streamsize num=1, int delim=eof) |
Ignoring the next num characters or encountering Delim early end, Delim is also ignored |
int sync () |
Clears the buffer associated with the stream, returns 0 for success, 1 for failure |
istream& seekg (Streampos POS) |
Sets the position of the input stream pointer to POS, POS is the absolute position |
istream& seekg (Streamoff off, Ios_base::seekdir) |
Setting the input stream pointer to the position relative to the path offset off, Ios_base::seekdir can take the following constants: Ios::beg (buffer start), ios::cur (current position), ios::end (end of buffer) |
Streampos Tellg () |
Returns the current position of the pointer |
ostream& SEEKP (Streampos pos) and ostream& SEEKP (Streamoff off, Ios_base::seekdir) |
Similar to SEEKG for input stream objects |
Streampos TELLP () |
Similar to TELLG for output stream objects |
C++:io Buffer