D
Dylan
I'm attempting to write an object's state to a std::stringstream and
then to restore that state by reading from the stringstream. The
writing is fine but I'm having problems reading. Here's a little prog
that demonstrates the problem:
#include <iostream>
#include <sstream>
int main()
{
//create a buffer containing "1,2,3"
std::stringstream ss;
ss << 1 << "," << 2 << "," << 3;
std::cout << "\n" << ss.str();
//I'd like to assign 1 to iVal1 and 2 to iVal2, leaving ",3" in ss
//(but the following doesn't work)
int iVal1, iVal2;
ss >> iVal1 >> iVal2;
std::cout << "\n" << iVal1 << "," << iVal2;
std::cout << "\n" << ss.str();
return 0;
}
//The output from this is
1,2,3
1, -858993460
1,2,3
//but I'd like it to be
1,2,3
1,2
3,
How can i achieve this?
Thanks!
then to restore that state by reading from the stringstream. The
writing is fine but I'm having problems reading. Here's a little prog
that demonstrates the problem:
#include <iostream>
#include <sstream>
int main()
{
//create a buffer containing "1,2,3"
std::stringstream ss;
ss << 1 << "," << 2 << "," << 3;
std::cout << "\n" << ss.str();
//I'd like to assign 1 to iVal1 and 2 to iVal2, leaving ",3" in ss
//(but the following doesn't work)
int iVal1, iVal2;
ss >> iVal1 >> iVal2;
std::cout << "\n" << iVal1 << "," << iVal2;
std::cout << "\n" << ss.str();
return 0;
}
//The output from this is
1,2,3
1, -858993460
1,2,3
//but I'd like it to be
1,2,3
1,2
3,
How can i achieve this?
Thanks!