-1

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, ',');
            line.append(readFromFile);
            count_1++;
        }
        cout << line << endl;
        count_1 = 0;
    }

'line' ends up having the value:

12345678910111213141516171819202122232425\n1

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.

Mark Wilcoxen
  • 69
  • 1
  • 10

1 Answers1

1

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

jhbh
  • 317
  • 4
  • 11
  • well...I did not think to do that, I thought you had to separate it by comma. I feel quite foolish now. Will mark as answered as soon as I can. – Mark Wilcoxen Oct 07 '16 at 19:52