嗨,我需要一些代码的帮助。我需要测试一个函数,但是每次尝试编译时都会出现编译器错误。这是我得到的错误:指针类型'void()()'和'const char'之间的比较缺少强制转换。
这是我的代码。
#include <iostream>
using namespace std;
void getInput();
bool gameGoing = true;
int main()
{
do{
cout << "hello world this is a test.\n";
getInput();
if(getInput == "false")
{
return 0;
}
}while(gameGoing = true);
}
void getInput()
{
string userInput;
cin >> userInput;
}
最佳答案
应该是
#include <iostream>
using namespace std;
string getInput();
bool gameGoing = true;
int main()
{
do
{
cout << "hello world this is a test.\n";
if(getInput() == "false")
return 0;
} while(gameGoing == true);
}
string getInput()
{
string userInput;
cin >> userInput;
return userInput;
}
我改变了什么:
getInput
函数中添加了返回类型,以便其结果不会被忽略if
比较,以再次实际比较getInput
函数的结果和"false"
值gameGoing
与true
值进行比较,而不是覆盖