在我尝试从文件读取到数组并显示我首先在不同的文件中单独工作之前,代码正在运行。现在我不知道出了什么问题,但它现在不会调试任何人都可以帮忙吗?
#include "Questions.h"
using namespace std;
int main ()
{
const int MAXITEMS = 15;
ifstream QuestionFile;
char a;
int count = 0;
string question[MAXITEMS];
string answers[10];
int userInput = 0;
int tries = 0;
bool isGameOver = false;
cout << "select 1 to start game" << endl; gives option to start and quit game
cout << "select 2 to quit game" << endl;
cin >> userInput;
if (userInput == 2)
{
isGameOver = true; to close game
return 0;
};
error message if 1 or 2 is not input
do
{
if (userInput!=1 && userInput!=2)
{
cout << " Your input is not valid! please try again:" << endl; error message
cout << "select 1 to start game" << endl;
cout << "select 2 to quit game" << endl;
cin >> userInput;
if (userInput == 2)
{
isGameOver = true;
return 0;
};
while (!(cin >> userInput)) error message
{
cin.clear(); clear the error flags
cin.ignore(INT_MAX, '\n'); discard the row
cout << "Your input is not valid! please try again: ";
cout << "select 1 to start game" << endl;
cout << "select 2 to quit game" << endl;
}
cout << userInput << endl;
}
reprisent all characters as number to stop while problem
when game starts gives option to select question and shows all questions
if(userInput == 1)
{
QuestionFile.open ("Questions2.txt.txt"); opening this file
if(!QuestionFile) file testing
cout<< " error opening file" << endl;
// system("pause");
//return-1;
// };
while(QuestionFile) while read is working display from file into array
{
cout << count << " " << question << endl; for display
QuestionFile >> question[count]; read into array
count++;
}
for (int i = 0; i < count ; ++i) displaying out the array
{cout << " array" << i << " is ::";
cout << question[i]<< endl;
}
cout << question[0]; reads in data
QuestionFile.close();
system ("pause");