U
utab
Dear all
the code below, there is sth wrong with string streams. I can not
bound the same string to a string stream second time. If I create
another string stream it is OK. Most probably there is sth that I am
missing about stream buffers.
1 #include <iostream>
2 #include <sstream>
3 #include <string>
4
5 using namespace std;
6
7 int main(){
8 unsigned index;
9 unsigned i;
10 char c;
11 double val;
12 string in("1 c 0.43");
13 istringstream strm;
14 strm.str(in);
15 strm >> index >> c >> val;
16 cout << index << " " << c << " " << val*0.2 << endl;
17 //istringstream strm1(in.c_str());
18 strm.str(in);
19 strm >> i;
20 cout << val << " " << i << endl;
21 return 0;
22 }
Output is:
1 c 0.086
0.43 3086289584
Best regards
the code below, there is sth wrong with string streams. I can not
bound the same string to a string stream second time. If I create
another string stream it is OK. Most probably there is sth that I am
missing about stream buffers.
1 #include <iostream>
2 #include <sstream>
3 #include <string>
4
5 using namespace std;
6
7 int main(){
8 unsigned index;
9 unsigned i;
10 char c;
11 double val;
12 string in("1 c 0.43");
13 istringstream strm;
14 strm.str(in);
15 strm >> index >> c >> val;
16 cout << index << " " << c << " " << val*0.2 << endl;
17 //istringstream strm1(in.c_str());
18 strm.str(in);
19 strm >> i;
20 cout << val << " " << i << endl;
21 return 0;
22 }
Output is:
1 c 0.086
0.43 3086289584
Best regards