文件处理出错
File handling gone wrong
代码在我尝试从文件读取到数组和显示之前运行,我首先在不同的文件中单独工作。现在我不知道出了什么问题,但它不会调试,现在谁能帮助请?
#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");
关闭主?您缺少大括号
"} "
相关文章:
- 警告处理为错误这里有什么问题
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 使用流处理接收到的数据
- 重载操作程序时出错>>用于类中的字符串 memebr
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 将事件处理程序添加到任何控件都会导致 Visual Studio 中出错
- 使用类处理文件时出错
- 处理数组时出错 C++
- 处理向量集时出错
- 我怎么能在处理字母和负数时出错呢
- LLVM的异常处理出错
- 文件处理出错
- c++ vsnprintf处理长字符串(或奇怪字符串)时出错
- C++-将文件处理程序传递到函数中以打开时出错
- 在 CPP 中处理对象时出错