So I'm trying to read a input file into a 2-dimensional array.
The problem I'm having is that I want only certain lines in my input file to be read but I just don't know where to put the second ignore in my code
Here is the input file called "Fruit.txt":
Oroblanco Grapefruit
Winter
Grapefruit
Gold Nugget Mandarin
Summer
Mandarin
BraeBurn Apple
Winter
Apple
And my code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int MAX_ROW = 6;
const int MAX_COL = 4;
void FileInput(string strAr[MAX_ROW][MAX_COL])
{
ifstream fin;
fin.open("Fruit.txt");
int columnIndex;
int rowIndex;
rowIndex = 0;
while(fin && rowIndex < MAX_ROW)
{
columnIndex = 0;
while(fin && columnIndex < MAX_COL)
{
getline(fin, strAr[rowIndex][columnIndex]);
fin.ignore(10000,'\n');
columnIndex++;
}
rowIndex++;
}
fin.close();
}
My code for now stores it like this:
Oroblanco Grapefruit // strAr[0][0]
Grapefruit // strAr[0][1]
Gold Nugget Mandarin // strAr[0][2]
Mandarin // strAr[0][3]
BraeBurn Apple // strAr[1][0]
Apple // strAr[1][1]
I want it to be like this:
Oroblanco Grapefruit // strAr[0][0]
Gold Nugget Mandarin // strAr[0][1]
BraeBurn Apple // strAr[0][2]
I just don't know where I should put the second ignore at. If I put it right after the first ignore, then it would skip more than what I want.