I am VERY new to C++ and attempting to read in some arrays from a text file with the following data:
Number_of_students 3
Number_of_assignments 3
Paul Smith 5 6 7
Tina Smith 6 7 7
Andrew Smith 4 5 10
What I need to do is put the names into an array and the numbers following them into a separate array. Below is my code, I am getting 0's whenever I try to output a value from one of the arrays.
#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
const int MAX_CLASS_SIZE = 100;
const int MAX_NUMBER_OF_ASSIGNMENTS = 100;
string names[MAX_CLASS_SIZE][2]
int scores[MAX_CLASS_SIZE][MAX_NUMBER_OF_ASSIGNMENTS]
int number_of_students
int number_of_assignments
ifstream file;
file.open("grades.txt");
if (file.is_open())
{
string nos;
string noa;
file >> nos >> number_of_students;
file >> noa >> number_of_assignments;
for (int i = 0; i < number_of_students; i++) {
for (int j = 0; j < 2; j++) {
for (int s = 0; s < number_of_assignments; s++) {
file >> names[i][j] >> scores[i][s];
}
}
}
file.close();
}
else cout << "Unable to open file";
return 0;
}