[英]C++ Expected Primary Expression before '<<' Endl
当我尝试编译以下代码时, expected primary-expression before '<<' token
编译错误消息expected primary-expression before '<<' token
我一直得到expected primary-expression before '<<' token
。 我很确定这与endl有关; 因为当我删除'<< endl; 从代码的每个部分都能正常工作
#include <cstdlib>
#include <iostream>
using namespace std;
int num1 = 0;
int funcNum1()
{
cout << num1; << endl;
int num1 = 2;
cout << num1; << endl;
return 0;
}
int main(int argc, char *argv[])
{
cout << num1; << end1;
int num1 = 1;
funcNum1();
cout << num1; << end1;
system("PAUSE");
return 0;
}
您在cout << num1; << end1;
行中犯了错误cout << num1; << end1;
cout << num1; << end1;
更改为
cout << num1 << endl;
在代码中的两个位置都可以这样做。
从该代码中可以看到,在num1
您有分号。 删除该分号(您的函数中也存在此问题)。 另外,您在endl
使用数字1代替l。 修复这两个错误,它应该可以工作。
int main(int argc, char *argv[])
{
cout << num1; << end1;
int num1 = 1;
funcNum1();
cout << num1; << end1;
system("PAUSE");
return 0;
}
在main()中,语法关闭:
int main(int argc, char *argv[]) {
cout << num1 << endl; // watch the semicolons, use "endl" not "end1"
int num1 = 1;
funcNum1();
cout << num1 << endl; // watch the semicolons, use "endl" not "end1"
system("PAUSE"); // system needs #include <stdlib.h>
return 0;
}
您需要嵌入在“ cstdlib”标头中的“ stdlib.h”来访问system()方法:看一下文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.