我試圖運行我的程序時收到此通知。在CandidateVotes.exe中引發0x50E6F1C0(ucrtbased.dll)異常:0xC0000005:訪問衝突讀取位置0x00000000
在CandidateVotes.exe中0x50E6F1C0(ucrtbased.dll)引發異常:0xC0000005:訪問衝突讀取位置0x00000000。
這裏是我的代碼:
編寫一個程序,允許用戶輸入的地方選舉五名候選人 以及每個候選人獲得的選票數的姓氏。 然後程序應該輸出每個候選人的姓名,收到的票數, 以及候選人收到的總票數的百分比。 你的程序也應該輸出選舉的獲勝者。
void main()
{
string name[5] = { 0 };
int votes[5] = { 0 };
int total = 0;
for (int i = 0; i < 5; i++)
{
cout << "What is the name of Candidate number " << i + 1 << "?" << endl;
cin >> name[i];
cout << "How many votes did " << name[i] << " receive?" << endl;
cin >> votes[i];
total += votes[i];
cout << total << endl;
}
system("pause");
}
'字符串名稱[5] = {0};' - >'字符串名稱[5];' –