I am extracting exactly 14 tokens in each line on a csv file, and my problem is that in any token if there are spaces in it, I want to preserve it, but I am using stringstream so when I try and extract the data, I'm excluding spaces apart of the same token and it's not inputting correctly and will mess up all data after that. I need a way to use stringstream but still be able to preserve spaces in the tokens. I am looking to extract exactly the third token(in my case), but it would be nice to know in general how can I for any token
Ex: The csv file would be:
PHIL, 100, Intro to Philosophy, 6, Bobby,... (all on one line)
I have a constructor which takes a reference to stringstream object which is supposed to initialize my data members. When I get to a token which commonly has spaces, it will stop at a space and in this example it would only take, "Intro" and then store that into my classTitle variable, but I want the entire, "Intro to Philosophy". I also have a field for a teacher's name, but there's almost no spaces in a person's first name. But in general, how do I preserve the spacing?
This is my constructor:
Course( stringstream &ss ){
ss >> dept >> courseNumber >> courseTitle >> numAs >> numBs >> numCs >> numDs >> numFs >> numIs >> numNRs
>> numSs >> numUs >> numWs >> instructor;
dump();
}
This is in main where I read the file, dump is just a function I am using to output the data that I get to verify if it's correct:
string dummyLine; // string meant to be used to skip over first line
getline(gradeFile, dummyLine);
while ( gradeFile.good() ){ // read until the end of the file
stringstream ss;
getline(gradeFile, input); // r)ead a line of input, stop at a comma
replace(input.begin(), input.end() , ',', ' ');
ss << input;
Course course(ss);
if ( count == 0 ){
//course.dump();
}
count++;
break;
}
But actually in my output I'm getting a bunch of 0's after 'Intro' in my real data even though the numbers in the csv file aren't 0, so that's also puzzling to me because I thought that each token after that would get the value that the token that I wanted to input would've got, unless it's because the other fields up to 13 were ints.