I'm writing some code in order to read some parameters values from a file.
I know that if, let's say, I have a stringstream
object stream
created from the string "10"
I can initialize a numeric variable defined as int var1;
just by typing:
stream >> var1;
What if now my stringstream
object is created from the string "10;3;4.5;3.2;"
and I have four variables declared as follows:
int var1;
int var2;
double var3;
double var4;
Can I write something like this:
stream >> var1;
stream >> var2;
stream >> var3;
stream >> var4;
in order to initialize all the four variables from this stream? Or my only option is to implement a simple parser to extract each value one at a time and then store that value into each one of them?
Well, in fact I tried it and it doesn't work. var1
gets initialized correctly but the other variables are all initialized to 0.
Can you explain why this doesn't work? Thank you in advance for your help.