[英]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.