Is is possible to stringstream this way? to convert from string to int?

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2011-02-20T05:16:41Z Indexed on 2011/02/20 7:25 UTC
Read the original article Hit count: 168

Is it possible to stringstream like this? I am trying to read with ifstream and convert it.

string things = "10 11 12 -10";
int i1;
int i2;
int i3;
int i4;
stringstream into;
into << things;
into >> i1;
into >> i2;
into >> i3;
into >> i4;

I expect it to be :

i1 = 10
i2 = 11
i3 = 12
i4 = -10

is that correct?

Can the same stringstream variable be used multiple times?

When I tried, the first time was ok but everything else later on is just 0.

© Stack Overflow or respective owner

Related posts about c++

Related posts about string