预期`;'在“cout”之前

时间:2012-02-04 22:47:52

标签: c++ dev-c++

嘿大家我是新手,很想得到一些帮助。我得到了一本名为C ++的书,没有Brian Overland的恐惧,我跟随所有的例子,但出于某种原因,这种情况发生了:

E:\ portableapps \ Dev-Cpp Portable \ App \ devcpp \ main.cpp在函数int main(int, char**)': 9 E:\portableapps\Dev-Cpp Portable\App\devcpp\main.cpp expected;'在“cout”之前  E:\ portableapps \ Dev-Cpp Portable \ App \ devcpp \ Makefile.win [Build Error] [main.o]错误1

书中的例子说写下面的代码并保存然后编译并运行它:

#include <iostream>
using namespace std;
int main() {
cout << "I am Blaxxon," <<endl;
cout << "the godlike computer." <<endl;
cout << "Fear me! <<endl;

system("PAUSE");
return 0;
}

它有时候工作正常,其他时候我必须这样写:

#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
cout << "I am Blaxxon," <<endl;
cout << "the godlike computer." <<endl;
cout << "Fear me! <<endl;

system("PAUSE");
return EXIT_SUCCESS;

否则它会显示一些错误,我认为这是一个编译错误; Dev-C ++便携式Beta版。

无论如何,本书指出如果省略这些字符<< endl;,程序将打印

我是Blaxxon,一个神圣的计算机。害怕我!

当然,只有一行。所以我尝试了但是我收到了这个错误:

E:\ portableapps \ Dev-Cpp Portable \ App \ devcpp \ print2.cpp在函数int main(int, char**)': 9 E:\portableapps\Dev-Cpp Portable\App\devcpp\print2.cpp expected;'在“cout”之前  E:\ portableapps \ Dev-Cpp Portable \ App \ devcpp \ Makefile.win [Build Error] [print2.o]错误1

它不会在单个内容中打印任何内容,只会显示一个systax错误。不知道它是什么。请帮忙。

3 个答案:

答案 0 :(得分:4)

你刚忘了

中的结束语
cout << "Fear me! << endl;

应该是

cout << "Fear me!" << endl;
//               ^ notice the closing quote

我认为所有IDE都有语法高亮。

答案 1 :(得分:1)

您错过了结尾"

cout << "Fear me! " << endl;

答案 2 :(得分:0)

cout << "Fear me! << endl;

您在字符串文字后缺少"