Reputation: 3
Im having a bit of trouble reading CSVs. I have multiple types of data, so i am not sure how to get this to work:
string, string, bool, bool, int
I cant simply use >>
to read in the data since the deliminator is not whitespace. scanf
doesnt work, since it needs a human input, not file input, getline
only reads in strings and also includes the \n
char for some reason.
how can i read my csv properly?
Upvotes: 0
Views: 421
Reputation: 14791
Another option (which isn't typically recommended for C++, though), is fscanf
. You're right that scanf
is no good for you, but fscanf
is its file-based equivalent.
Another canonical solution typically employed in C, but which isn't so strongly recommended in C++, is to go ahead and use getline
, and then use strtok
or a simple parser to parse each line.
Upvotes: 2
Reputation: 22406
You CAN use getline. There's an overload where the third argument passed can be a char for the delimiter. Just throw it all in a loop
Upvotes: 5