我正在尝试编写一个程序,从文件中读取名称和票数。但是我无法让 char 数组从文件中正确读取。
void Output(char candidateLastName[][10], long votesRecieved[])
{
ifstream Electionr("Election.dat");
int loop = 0;
cout << left << setw(10) << "Candidate" << setw(5) << "Votes" << endl;
Electionr >> candidateLastName[0][10];
Electionr >> votesRecieved[0];
cout << setw(10) << candidateLastName[0] << setw(5)
<< votesRecieved[0] << endl;
for(int loop = 1; loop < 5; loop++)
{
Electionr >> candidateLastName[0][10];
Electionr >> votesRecieved[loop];
cout << setw(10) << candidateLastName << setw(5)
<< votesRecieved[loop] << endl;
}
Electionr.close();
}
虽然文件中的数字正确读取,但字符不会。