Hello everyone! I am currently reading in a table separated by spaces which looks like this:
1 2 3 4
Pol1 M N 20 100000 1 .04 99
Pol2 F S 30 100000 1 .05 99
Pol3 M S 72 750000 1 .03 99
Pol4 F N 45 1000000 1 .05 99
However I would like to alter the table so that instead of it being separated by spaces it is separated by only commas. So the new table looks like this:
while (!datafile.eof()){
getline(datafile, field, ',');
stringstream ss(field);
ss >> policy >> gender >> smoker_status >> age >> death_ben >> db_option >> interest >> end_age;
but it ended my while loop after only the first policy (only read in first row in table) and didn't read in the 2nd, 3rd, or 4th. What am I doing wrong?? Thank you!
string line;
while (getline (datafile, line)) // read one record upto \n
{ stringstream ss(line);
getline (ss, policy, ','); // get first field up to delim
getlne (ss, gender, ','); // get second field up to delim
// etc for remaining fields.
// numeric fields will require an extra level of parsing
string temp4;
getlne (ss, temp4, ','); // get numeric field upto delim
stringstream field4 (temp4);
field4 >> Age;
}