2013-10-27 186 views
-5

我最近決定嘗試使用C++,並且馬上就關閉了,我不知道自己在做什麼。 我安裝了Microsoft Visual C++ Express 2010.與Eclipse中的Java一樣,我創建了一個新項目並在源文件夾中創建一個新文件。 這裏是我的代碼:無法編譯Hello World程序

#include <iostream> 
using namespace std; 

int() main 
{ 
    cout << "Hello World!\n"; 
    return 0; 
} 

而且我這是我所得到的,當我嘗試建立:

1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------ 
1> Hello.cpp 
1>c:\users\dylan\documents\visual studio 2010\projects\helloworld\helloworld\hello.cpp(4): error C2059: syntax error : ')' 
1>c:\users\dylan\documents\visual studio 2010\projects\helloworld\helloworld\hello.cpp(5): error C2143: syntax error : missing ';' before '{' 
1>c:\users\dylan\documents\visual studio 2010\projects\helloworld\helloworld\hello.cpp(5): error C2447: '{' : missing function header (old-style formal list?) 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

編輯:啊該死的,這是一個令人難以置信的愚蠢的錯誤。顯然我需要更仔細地看待文本。感謝所有迴應的人。

+7

int()main'應該是int main()'。 – jrok

+5

爲什麼在你決定說出一種你以前從未用過的新語言「讓我們問Stack Overflow」而不是「Let's go and learn this language」之後,WHY是你的第一反應? –

+1

Man ...這是一個**啞巴**問題。對不起,但是。嚴重的是,**爲什麼你不能仔細閱讀這個初學者的教程仔細?** – 2013-10-27 18:51:30

回答

4
int() main 

應該是

int main() 

函數簽名的一般形式(簡體)

[返回類型] [函數名] [參數類型] [參數名稱] , ...

[返回類型] [函數名] ()

如果該函數不要求參數。

2

我注意到的第一件事是,禁忌應該在主關鍵字之後,而不是在它之前。

0

有一個語法錯誤 - 第4行應該是int main()