我有一个变量,它包含游戏的分数。在if语句中无法访问变量
我的变量是如下图所示
得分在main.cpp中的顶部声明,并在显示功能也包含以下
代码计算的if语句而不是内部访问和正确的外cout << score << endl; //works
if(!justFinished){
cout << score << endl; // doesn't work prints a large negative number
endTime = time(NULL);
ifstream highscoreFile;
highscoreFile.open("highscores.txt");
if(highscoreFile.good()){
highscoreFile.close();
}else{
std::ofstream outfile ("highscores.txt");
cout << score << endl;
outfile << score << std::endl;
outfile.close();
}
justFinished = true;
}
cout << score << endl;//works
编辑: 已经意识到我的问题,当我打印出它循环了很多次,所以我没有看到他们的第一个循环都没有工作,因此我认为其他人在工作时事实上他们不是第一次迭代。
变量'score'声明在哪里,你分配了什么? – Syntactic 2010-04-20 14:54:09
什么编译器/操作系统?你能否显示声明的分数/分数? – Zanson 2010-04-20 15:00:33
得分是整数类型还是类的实例? – 2010-04-20 15:16:50