Hi again,
In the following program I expected step 3 to assign the values 1 and
2 to iVal1 and iVal2 yet it appears ss.seekg(0, std::ios::beg) does
not move the read position back to the beginning of the stream as
expected.
//-----------------------------------------------------------------------------
#include <iostream>
#include <sstream>
int main()
{
//1. create a buffer containing "1,2"
std::stringstream ss;
ss << 1 << " " << 2;
std::cout << "\n" << ss.str();
//2. read the values 1 & 2 from the buffer and assign to iVal1 &
iVal2
int iVal1=-1, iVal2=-1;
ss >> iVal1 >> iVal2;
std::cout << "\n" << iVal1 << "," << iVal2;
//3. now move the read position back to the beginning of the stream
and read
//the values again
ss.seekg(0, std::ios::beg);
iVal1=-1; iVal2=-1;
ss >> iVal1 >> iVal2;
std::cout << "\n" << iVal1 << "," << iVal2;
//4. write the buffer to make sure it still contains "1 2" [OK]
cout << "\n" << ss.str();
return 0;
}
//-------------------------------------------------------------------------------
output from above is:
1,2
1,2
-1,-1
1,2
How can i move the read position back to the start of the buffer?
thanks