C++ stringstream reads all zero's
- by user69514
I have a file which contains three integers per line. When I read the line I use a stringstream to separate the values, but it only reads the first value as it is. The other two are read as zero's.
ifstream inputstream(filename.c_str());
if( inputstream.is_open() ){
string line;
stringstream ss;
while( getline(inputstream, line) ){
//check line and extract elements
int id;
double income;
int members;
ss.clear();
ss.str(line);
ss >> id >> income >> members;
In the case above, id is extracted correctly, but income, and members get assigned zero instead of the actual value.