I am writing a program that reads a comma-delimited file. There are several words on each line that will each be assigned to a string variable, each line in the file is a record, and the file contains several records.
I am using getline with a delimiter,
e.g. getline(inputstream, string, delimiter)
The problem I am having is that this command reads through the newline, up until the next comma (my delimiter), so that where I should have two strings, I get one long string.
My code:
while(!input.eof())
{
getline(input, token, ',')
//Do some stuff to the token string here
}
For instance if the file contains
Bob,Saget,Pimp
Carrot,Top,Comedian
My getline command creates the following strings:
Bob, Saget, PimpCarrot, Top, Comedian.
So essentially, how do I use the comma and the newline character as delimiters for the same read function?