I am trying to go through a CSV file that is formatted like this:
4305,2.7,59338,"Autauga County, AL"
14064,2.7,57588,"Baldwin County, AL"
Here is an adapted version of the code:
using namespace std;
int main(){
string newl;
//getline(cin, newl);
while(getline(cin,newl,',')){
double cases1 = stod(newl);
//cin.ignore();
cout << cases1 << ' ';
cout << "numbaone" << endl;
getline(cin,newl,',');
//cin.ignore();
double unemploymentrate1 = stod(newl);
cout << unemploymentrate1 << ' ';
cout << "numbatwo" << endl;
getline(cin,newl,',');
double income1 = stod(newl);
cout << income1 << ' ';
cout << "numbathree" << endl;
cin.ignore();
getline(cin,newl);
}
}
When I just input one line it gives me the correct output which for
1882,3.1,46064,"Bibb County, AL
" is
1882 numbaone
3.1 numbatwo
46064 numbathree
However, when I copy and paste multiple lines as input such as
1530,3.8,34382,"Barbour County, AL"
1882,3.1,46064,"Bibb County, AL"
the output gets really messed up:
1530,3.8,34382,"Barbour County, AL"
1882,31530 numbaone
3.8 numbatwo
34382 numbathree
.1,46064,"Bibb County, AL"
1882 numbaone
3.1 numbatwo
46064 numbathree
any help would be very much appreciated.
question from:
https://stackoverflow.com/questions/65599605/not-sure-why-i-am-getting-c-error-with-cin-and-getline