文件处理出错

File handling gone wrong

本文关键字:出错 处理 文件      更新时间:2023-10-16

代码在我尝试从文件读取到数组和显示之前运行,我首先在不同的文件中单独工作。现在我不知道出了什么问题,但它不会调试,现在谁能帮助请?

#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");

关闭主?您缺少大括号

"} "