V
vigacmoe
I was trying to cast some strings to integers with stringstream, then
this strange problem poped up.
Here is my test code:
stringstream conv;
string from;
int to;
from = "1";
conv << from;
conv >> to;
from = "2";
conv << from;
conv >> to;
The first casting worked fine, but the second casting didn't work at
all.
conv.str() returned "1" after 'from = "2"; conv << from;' was executed.
Then I explicitly changed the buffer of conv, like this:
conv.str("1");
conv >> to;
conv.str("2");
conv >> to;
Still, the first casting worked perfectly, the second one failed, to ==
1.
I'm wondering I've terribly misunderstanding something, sorry if I'm
asking the obvious.
this strange problem poped up.
Here is my test code:
stringstream conv;
string from;
int to;
from = "1";
conv << from;
conv >> to;
from = "2";
conv << from;
conv >> to;
The first casting worked fine, but the second casting didn't work at
all.
conv.str() returned "1" after 'from = "2"; conv << from;' was executed.
Then I explicitly changed the buffer of conv, like this:
conv.str("1");
conv >> to;
conv.str("2");
conv >> to;
Still, the first casting worked perfectly, the second one failed, to ==
1.
I'm wondering I've terribly misunderstanding something, sorry if I'm
asking the obvious.