The difference between ies () and readsome () in IFStream.
A very interesting bug has a very interesting bug. The program reads the data in a specific binaries, which is processed, but whenever the amount of data exceeds a certain value (this value is not large, 400K) is running. The result is wrong.
Tracing BUG is one of the basic skills of programmers and is one of the most powerful places. This BUG eventually captured by a colleague after 3 days of being hired. The reason is indeed because I have written the FSREAM :: readsome () function in the module I write. Change into fsream :: read ().
In addition to horrifying, I have seen the explanation of flow in detail.
First, FStream is an instance of the Basic_FStream template class about char.
Typedef Basic_fstream
Basic_fstream is derived from Basic_iostream
Template
Class Basic_fstream: Public Basic_ioStream
Basic_ioStream is derived from Basic_istream and Basic_OSCREAM.
Template
Class Basic_iostream: Public Basic_istream
Public Basic_OStream
The fstream :: readsome we use is actually Basic_istream :: readsome ().
Basic_istream is derived from Basic_ios
Template
Class Basic_istream
: Virtual public Basic_ios
Basic_ios is derived from iOS_BASE
Template
Class Basic_ios: Public iOS_BASE
The derived relationship is as follows:
In the implementation of the stream, the method of buffer I / O is taken. Each STREAM object has a streambuf, and the operation of the flow is the operation of the buffer until there is forced him and the buffer. Synchronous operation.
The difference between read () and readsome () is that readsome () does not force the synchronous buffer, while read () reads, if the data in the buffer is found, try to be related to the dependent data source ( Here is the file) to read.
The readsome () function is called gcount () to detect how many bytes are operated. The good () function can also be detected, and I have not done.
I originally selected Readsome () whose read () is to operate Charactor, and readsome () is to operate binary.