Article ID: 104634
Article Last Modified on 12/1/2003
The reserve area, put area, and get area are introduced in the streambuf class description. The put area and the get area are always the same for filebuf objects. Also, the get pointer and put pointers are tied; when one moves, so does the other.
Although the filebuf object's get and put pointers are theoretically independent, the get area and the put area cannot both be active at the same time.
/* Compile options needed: None. Build as a console .EXE for Windows NT
*/
#include <fstream.h>
#include <strstrea.h>
#include <assert.h>
#undef NDEBUG // Make sure assert works.
void main()
{
fstream stream("test",ios::in | ios::out | ios::binary);
int temp;
char input;
cout << "\n\nOpened binary file test" << endl;
cout << "Get pointer is " << hex << stream.tellg() << endl;
cout << "Put pointer is " << hex << stream.tellp() << endl;
cout << "Now writing 256 bytes..." << endl;
for(temp = 0;temp < 256;temp++)
{
stream.put((char)temp);
}
cout << "Get pointer is " << hex << stream.tellg() << endl;
cout << "Put pointer is " << hex << stream.tellp() << endl;
cout << "\nNow setting the put pointer to hex 50" << endl;
stream.seekp(0x50);
cout << "Get pointer is " << hex << stream.tellg() << endl;
cout << "Put pointer is " << hex << stream.tellp() << endl;
cout << "\nNow setting the get pointer to hex 40" << endl;
stream.seekg(0x40);
cout << "Get pointer is " << hex << stream.tellg() << endl;
cout << "Put pointer is " << hex << stream.tellp() << endl;
cout << "\nNow writing one character" << endl;
stream.put('a');
cout << "Get pointer is " << hex << stream.tellg() << endl;
cout << "Put pointer is " << hex << stream.tellp() << endl;
cout << "\nNow reading one character" << endl;
stream.get(input);
cout << "Get pointer is " << hex << stream.tellg() << endl;
cout << "Put pointer is " << hex << stream.tellp() << endl;
stream.close();
}
Keywords: kbinfo kblangcpp kbcode KB104634