K
k:arel
today i've discovered the istringstream object
i'm trying to read a string and split it up in a number of fields,
consisting of integers and strings
it's for a protocol that sends messages with:
* message code, pe. 1 for HELLO
* message content, pe. 5 (seed)
both field are separated by @+@
/* *********************************************** */
istringstream in;
in.str("1@+@5");
int msgcode=-1;
int seed=-1;
string spacer;
in >> msgcode >> spacer >> seed;
cout<<"msgcode="<<msgcode<<",spacer="<<spacer<<",seed="<<seed<<endl;
/* *********************************************** */
yet, when i run this, the output is:
msgcode=1,spacer=@+@5,seed=-1
the 5 always belongs to the string "spacer"
also replacing the @+@ by a space or taking a char* as data type for
"spacer" doesn't put the 5 in the "seed"
the string "spacer" alway reaches to the end (also if we set there 555
instead of just 5), it's probably because the stream can't tell where
to end the string and start the integer...
has anybody any idea how i could bypass this?
i'm trying to read a string and split it up in a number of fields,
consisting of integers and strings
it's for a protocol that sends messages with:
* message code, pe. 1 for HELLO
* message content, pe. 5 (seed)
both field are separated by @+@
/* *********************************************** */
istringstream in;
in.str("1@+@5");
int msgcode=-1;
int seed=-1;
string spacer;
in >> msgcode >> spacer >> seed;
cout<<"msgcode="<<msgcode<<",spacer="<<spacer<<",seed="<<seed<<endl;
/* *********************************************** */
yet, when i run this, the output is:
msgcode=1,spacer=@+@5,seed=-1
the 5 always belongs to the string "spacer"
also replacing the @+@ by a space or taking a char* as data type for
"spacer" doesn't put the 5 in the "seed"
the string "spacer" alway reaches to the end (also if we set there 555
instead of just 5), it's probably because the stream can't tell where
to end the string and start the integer...
has anybody any idea how i could bypass this?