快速概要:我可以正确地将数据写入文件中(我已经检查了.txt文件并且它完全按照应有的方式显示)但是我可以读回的是输入的最后一个数字。因此,如果我输入的最后一个测验等级是85,那就是它将回读的所有内容。 (studentNumber读回来很好。) 谢谢大家!还在这里学习......
while (answer == 1)
{
cout << "What is the student ID?\n";
cin >> studentNumber;
cout << "\n";
cout << "How many quizzes did you take?\n";
cin >> numQuiz;
outputFile << "\n";
outputFile << studentNumber << "\n";
outputFile << "Number of quizzes: " << numQuiz << "\t" "Grades: ";
for (int quiz = 1; quiz <= numQuiz; quiz++)
{
cout << "Please enter the score for quiz " << quiz << "\t";
cin >> score;
total += score;
// cout << "The score is " << score << " .\n";
outputFile << score << "\t"; }
// outputFile << total;
cout << "Do you have a student's grades to input?\nIf yes, type 1. If no, type 0.\n";
cin >> answer;
cin.ignore();
}
outputFile.close();
fstream inputFile;
inputFile.open("grades2.txt");
inputFile >> studentNumber;
cout << studentNumber << "\n";
inputFile >> score;
cout << score << "\n";
答案 0 :(得分:1)
您使用错误的运算符来读取数据。而不是
template <typename T>
class List;
class bigInt {
public:
List<int> values;
bigInt();
bigInt add(bigInt);
bigInt mul(bigInt);
bigInt pow(int);
};
你需要使用
inputFile << studentNumber;