2014-03-24 133 views
4

我是新來的編程C++,並試圖通過網站學習我自己(learncpp.com),雖然我已經停留在編譯我的第一個程序=(。他們使用Visual Studio編程他們的代碼,並因爲我使用的是MacBook,我只是用vi和終端(或我應該使用別的東西嗎?)致命錯誤:'stdafx.h'文件未找到

這裏的helloworld.cpp程序我寫基於教程:

#include "stdafx.h" 
#include <iostream> 
{ 
    std::cout <<"Hello World!" <<std::end1; 
    return 0; 
} 
我編譯時出現(gcc -Wall hello.cpp)

我得到這個錯誤:

helloworld.cpp:1:10: fatal error: 'stdafx.h' file not found 

#include "stdafx.h" 
     ^
1 error generated. 

任何人都可以告訴我如何解決這個問題?

+3

你嘗試,你知道,錯誤刪除的行? – this

+1

刪除'#include「stdafx.h」'。 – haccks

+2

你不需要該文件,只需將其刪除即可。這是針對Visual Studio特定的「預編譯頭文件」,這是您稍後將介紹的一個概念。歡迎來到SO! – OMGtechy

回答

1

兩個問題: a)stdafx.h不需要(如其他人注意的)。 b)'end1'應該是'end1'(注意字母'l'與數字'1')。

+1

c)需要'int main()' –

+0

^yea我得到了之前:)謝謝 – JackieZ3895

9
  1. stdafx.h是visual studio使用的預編譯頭,你不需要這個。
  2. 你似乎已經錯過了int main()功能
  3. 這是std::endlstd::end1

因此,像這樣:

#include <iostream> 
int main() { 
    std::cout <<"Hello World!" <<std::endl; 
    return 0; 
}