#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <stdlib.h>
using namespace std;
int gradeExam(string answerKeyARR[]);
int main()
{
const int QUESTIONS = 10;
const int MAX_STUDENTS = 250;
ifstream inFile;
ofstream outFile;
inFile.open("grade_data.txt");
outFile.open("grade_report.txt");
string ansKey;
inFile >> ansKey;
string answerKeyARR[QUESTIONS];
//Loop for storing each answer into an array rather than all in a single string.
for (int j = 0; j < QUESTIONS; j++)
{
answerKeyARR[j] = ansKey.substr(j,1);
}
int i = 0;
int numStudents = 0;
string studentAnswers[MAX_STUDENTS];
//Loop to read in all answers into array and count number of students.
while (!inFile.eof())
{
inFile >> studentAnswers[i];
numStudents++;
i++;
}
//WHY DOES IT CRASH HERE?!
string studentAnswersARR[numStudents][QUESTIONS];
for (int k = 0; k < numStudents; k++)
{
for (int l = 0; l < QUESTIONS; l++)
{
studentAnswersARR[k][l] = studentAnswers[l].substr(l,1);
cout << studentAnswersARR[k][l];
}
}
inFile.close();
outFile.close();
return 0;
}
好的,所以基本上,一旦它到達它的子字符串的部分,它崩潰。它可以很好地檢索答案的答案,所以爲什麼當它到達這一點時它會崩潰?對於基本編碼2,這仍然是WIP。 另外,當我將變量'l'更改爲位置0時,它可以工作。是什麼賦予了?爲什麼當我到達2D陣列時會崩潰? out_of_range
'串studentAnswersARR [numStudents] [問題];'這不是標準C++。它不應該編譯。如果它編譯,它是一個非標準擴展,其規則由編譯器供應商決定。 – PaulMcKenzie 2015-02-06 23:25:27
哦,它不是標準的C++,因爲你使用一個變量來表示數組中的項目數。數組聲明時必須使用編譯時間常量。 – PaulMcKenzie 2015-02-06 23:29:52