致命错误:'stdafx.h'文件未找到

问题描述:

我是新来的编程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

两个问题: a)stdafx.h不需要(如其他人注意的)。 b)'end1'应该是'end1'(注意字母'l'与数字'1')。

+1

c)需要'int main()' –

+0

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

  1. stdafx.h是visual studio使用的预编译头,你不需要这个。
  2. 你似乎已经错过了int main()功能
  3. 这是std::endlstd::end1

因此,像这样:

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