I would like to ifstream a csv file and output several columns( but not the whole thing) how would i write the code so that it only reads ie. column D and G?
Steps:
1. Use the getline function, but use the comma to delimit.
2. Check which column you are in. Output the cell only if you are in columns 3 to 6 (D to G).
3. When a new line is found, reset the counter that tracks your current column.
I tried something out below. I wasn't sure how to check for the new line so the code is incomplete:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
ifstream input("MyFile.csv");
ofstream output("DthruG.csv");
string Cell;
int Column = 0;
while (!input.eof())
{
getline(input,Cell, ',');
if (Column >= 3 && Column <= 6)
output << Cell << ',';
if ("Cell contains '\n'") Column = 0;
else Column++;
}