Lets say there is a competition, and we have x races, and y contestants. Each race, every contestant gets a point between 0 and 10. So there is a file, looking something like this( without the dots, of course):
- Chet 10 Katie 8 Mark 3 Rachel 5
- Chet 3 Katie 9 Mark 6 Rachel 8
- Chet 6 Katie 6 Mark 7 Rachel 0
My problem is that here the strings and integers are alternating, and I dont know how to put them into the multidimensional-array.
Below is how I would do this, if there were only integers in a file. Is it possible to modify this so I can use it with my program?
string x;
int score,row=0,column=0;
int marray[10][10] = {{0}};
string filename;
ifstream fileIN;
cout<<"Type in the name of the file!"<<endl;
cin>> filename;
fileIN.open(filename);
while(fileIN.good()) //reading the data file
{
while(getline(fileIN, x))
{
istringstream stream(x);
column=0;
while(stream >> score)
{
marray[row][column] = score;
column++;
}
row++;
}
}