I am writing a program that needs to load a small database from a .csv file. Normally I would just look for the ',' character with getline(file, data, ',') to find each new cell but I can't do that here. Some of the cells have strings with commas in them and when I do this it splits some of the cells. So my question is how can I read each cell without looking for the commas? Is there a simple way I don't know about to grab just the next cell instead of looking for the comma character?
Asked
Active
Viewed 88 times
0
-
2If you want a robust solution, probably best to use a third-party library. – Neil Kirk Oct 11 '15 at 21:15
-
So what is "the next cell"? How do you recognize it? Are there spaces, have all the cells the same width? – JeffRSon Oct 11 '15 at 21:16
-
csv is by default a spreadsheet that opens in excel. C++ sees it as a text file with cells separated by commas and rows separated by newlines. I'm not sure how excel distinguishes between the new cell character and a regular comma. – Jack Oct 11 '15 at 21:20
-
1@Jack - Excel can enclose cell values in quotes. The quoted strings can contains commas (that are not separators). See this question [Dealing with commas in a CSV file](http://stackoverflow.com/questions/769621/dealing-with-commas-in-a-csv-file?rq=1) – Bo Persson Oct 11 '15 at 21:31