进程返回-1073741819(0xC0000005)

时间:2016-04-08 14:45:34

标签: c++ memory

在此程序中,用户输入座位和行号。用户值转到功能以查看座位是否是有效座位或座位是否已被占用。如果座位有效,程序将正确运行。但是,当座位无效时,程序崩溃并收到内存错误(进程返回-1073741819(0xC0000005))。

检查有效座位的功能:

 bool valid_seat(string seatingArray[][COLS], int userRow, int userColumn)
{
string userSelection = seatingArray[userRow - 1][userColumn -1];

if(userRow > 0 && userRow <= 9 && userColumn > 0 && userColumn <=8 && userSelection != " X ") //valid user entry
    return true;

else
    return false;
}

用户输入信息

    void availability(string seatingArray[][COLS], int& userRow, int& userColumn)
{
    do
    {
    cout << "Please select a theatre row: ";
        cin >> userRow;


    cout << "Please select a theatre column: ";
        cin >> userColumn;

    if(valid_seat(seatingArray, userRow, userColumn)) //if the user chose a valid seat, escape the loop
    {
    //display seat chosen
    cout << endl << "Thank you for choosing seat# " << userRow << ": " << userColumn << endl;

    //display ticket price
    cout << "The price for this seat is: " << seatingArray[userRow - 1][userColumn - 1] << endl;
    }
   else //if the seat IS NOT valid
   {
        cout << "Sorry, please choose another seat. The one you chose is unavailable!" << endl << endl << endl;
        Sleep(3000);
        system("CLS");
        display_theatre(seatingArray);
   }

} while(!valid_seat(seatingArray, userRow, userColumn));

}

1 个答案:

答案 0 :(得分:1)

您需要检查数组索引是否位于访问数组之前的数组范围内。否则该行访问越界内存:

private static ModelMetadata FromModel(ViewDataDictionary viewData, ModelMetadataProvider metadataProvider)
{
     return viewData.ModelMetadata ?? GetMetadataFromProvider(null, typeof(string), null, null, metadataProvider);
}