好的,我一直收到以下错误消息:
g++ -c -o guess.o guess.cpp
guess.cpp: In function ‘int main()’:
guess.cpp:70:7: error: expected ‘}’ at end of input
}
^
guess.cpp:70:7: error: expected ‘}’ at end of input
guess.cpp:70:7: error: expected ‘}’ at end of input
make: *** [guess.o] Error 1
它指的是我的代码的最后一部分:
cout << "Think of an integer between 1 and 1000. I will try to guess it." << endl;
bool result = doGuesses(0, 1001);
{
if (!result)
{
cout << " and is between 1 and 1000." << endl;
cout << "\n\nI demand a rematch!" << endl;
}
}
我删除了}并将其添加回来,我仍然继续收到相同的错误消息。我做错了什么?
答案 0 :(得分:1)
MAKEFILE
这对我来说很好看。但是有几个问题。
guess:yesno.o guess.o g++ guess yesno.o guess.o
g++
需要-o
选项来命名输出文件。它与您在命令行中运行它的语法相同。我会在结肠后放一个空格。但我不确定这是否是强制性的。
guess.o: yesno.h yesno.o: yesno.h
guess.o 和 yesno.o 还需要与各自的cpp文件的依赖关系。
像这样:
guess.o: guess.cpp yesno.h
答案 1 :(得分:1)
错误不言而喻。
您的包含警示会尝试测试无效的宏名称yesno.h
。它应该是yesno_h
,以匹配以下定义。
您的标头尝试包含自身,但作为系统标头。它不应该这样做。
你想要更像
的东西#ifndef yesno_h
#define yesno_h
// Return true if response is "yes", "y", or any upper/lowercase
// variant of those two strings.
bool yesNo (std::string response);
#endif