文件处理出错了

时间:2013-04-28 17:19:12

标签: c++ visual-c++ file-handling

代码在我尝试从文件读取到数组之前运行并显示我首先在另一个文件中单独工作。现在我不知道出了什么问题,但它现在不能调试,任何人都可以帮忙吗?

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

1 个答案:

答案 0 :(得分:0)

关闭你的主?你错过了大括号

“}”