I got my program to read from a .csv file and output the data but I don't want it to output the first line. I've tried to use getline(data, line);
and stream.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
. While it does skip the first line, the last two lines print twice and are mixed up.
string ID;
string sentenceIn;
string servedIn;
int sentence;
int served;
string lastName;
string firstName;
vector<string> idNum;
vector<string> sentenceLen;
vector<string> servedTime;
vector<string> lastNameIn;
vector<string> firstNameIn;
ifstream data("prisoner_data.csv");
if (data.is_open())
{
cout << "File opened successfully." << endl << endl;
while (data.good()) // !someStream.eof()
{
getline(data, ID, ',');
cout << ID << " ";
idNum.push_back(ID);
getline(data, sentenceIn, ',');
cout << sentenceIn << " ";
sentenceLen.push_back(sentenceIn);
istringstream(sentenceIn) >> sentence;
getline(data, servedIn, ',');
cout << servedIn << " ";
servedTime.push_back(servedIn);
istringstream(servedIn) >> served;
getline(data, lastName, ',');
lastNameIn.push_back(lastName);
cout << lastName << " ";
getline(data, firstName, ',');
firstNameIn.push_back(firstName);
cout << firstName << " ";
}
}
What can I do to skip the first line without messing up the last?