Essentially, I have an assignment where I must read from a file and store the data from the file into an array and a 2D array.
The file says this:
John Smith, 5, 10, 15, 10, 11, 14,
Mary Doe, 4, 15, 13, 25, 10, 13,
Larry Tran, 3, 14, 20, 12, 18, 11,
Tom Johnson, 5, 10, 11, 15, 17, 12,
Bella Morrison, 4, 12, 18, 13, 18, 14,
$
It is like a class with the integers being scores. I must store the names into a 1 dimensional array, and store the scores in a 2 dimensional parallel array. I have stored the names into an array, at least I believe I have, after having done some searching in the forum. However I am still having trouble finding out how to store the scores.
My code currently looks like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
const int scores = 6;
ifstream myfile;
myfile.open("CPSC121data.txt");
string names[5];
char delim = ',';
string numbers;
if (myfile)
{
for (int i = 0; i < 5; i++)
{
while (getline(myfile, names[i], delim) && getline(myfile, numbers))
}
}
system("PAUSE");
return 0;
}
|