Why does my program not output:
10
1.546
,Apple 1
instead of
10
1
<empty space>
here's my program:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main () {
string str = "10,1.546,Apple 1";
istringstream stream (str);
int a;
double b;
string c, dummy;
stream >> a >> dummy >> b >> dummy >> c;
cout << a << endl;
cout << b << endl;
cout << c << endl;
return 0;
}
Basically I am trying to parse the comma-separated strings, any smoother way to do this would help me immense.
See Question&Answers more detail:os