I need to parse the following string:
4210650,"GENERAL MCLANE SCHOOL DISTRICT","KG-12",18037,2862,142
int each indavidual part seperated by the commas and with the quotation marks removed?
I use getline to bring it in as a temp string.
I need to parse the following string:
4210650,"GENERAL MCLANE SCHOOL DISTRICT","KG-12",18037,2862,142
int each indavidual part seperated by the commas and with the quotation marks removed?
I use getline to bring it in as a temp string.
Put the temp string into a stringstream, then use getline again, but this time with ',' as the delimiter. Then convert the values that don't start with a quote to int (or whatever), and the ones that do you can just use erase to erase the first and last characters from the string.
So what you are saying is to have a string say
temp_string.
and use getline for on it.......what would be the correct syntax to do that....I thought getline was only for fstreams????
Since a string is really an array of characters, you could read in each char from the string untill a , is encountered.
If you encounter a quotation, do not read it in to the new string, but read into a string.
Otherwise, read into a temporary string, and then convert it into an integer.
The getline function is for any input stream: cin, ifstream, istringstream and others. Once you have your temp_string, create an istringstream and pass it as a parameter to the constructor. Then you can use your istringstream with getline. If you haven't already, I'm sure you could search and find some examples of istringstream or just stringstream.