Mark Wilcoxen Mark Wilcoxen - 10 months ago 39
C++ Question

"New Line" connected to value when reading in a CSV?

I am currently trying to read in a CSV file to place it into an array, but when I execute the code, the program seems to read over the endline to the next comma which messes up my output. Here is the code:

while (!inFile.eof()) {
string line = "";
while (count_1 <= numValuesPerLine) {
getline(inFile, readFromFile, ',');
cout << line << endl;
count_1 = 0;

'line' ends up having the value:


which when I print it, places that newline next to '25' and messes up the output.

(numValuesPerLine = 25 and count_1 is initialized outside of the loop)

I looked around for a similar answer but I could not find anything exactly like what I am trying to do, any help would be greatly appreciated, thank you.

Answer Source

you changed the delimiter from \n to , so of course the newline is kept as part of the input