c++ - fatal error : 'stdafx.h' file not found

标签 c++ c

我是 C++ 编程的新手,我正在尝试通过网站 (learncpp.com) 学习自己,尽管我已经坚持编译我的第一个程序 =( 。他们使用 Visual Studio 来编写他们的代码,因为我使用的是 macbook ,我只使用 vi 和终端(或者我应该使用其他东西吗?)

下面是我根据教程写的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.

谁能告诉我如何解决这个问题?

最佳答案

  1. stdafx.h 是 Visual Studio 使用的预编译头文件,您不需要它。
  2. 您似乎错过了 int main() 函数
  3. 它是 std::endl 而不是 std::end1

所以像这样:

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

关于c++ - fatal error : 'stdafx.h' file not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22621928/

相关文章:

c++ - 当我使用 Qthread::sleep 更新进度条时 Qt 崩溃/不出现

c++ - 查询结构或类的成员

c++ - 着色器中自己的 double cos() 实现的结果是 NaN,但在 CPU 上运行良好。出了什么问题?

C++ 基于文本的 RPG 库存系统

c++ - 谁能告诉我这是什么意思

c - 如何使用具有多个变量的结构初始化链表

c++ - 使用位域输出结构大小

c++ - (++i) 和 (i++) 的区别

c - 在 C 中自动注册单元测试

c++ - 如何从外部文件调用C++函数?