我是 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.
谁能告诉我如何解决这个问题?
最佳答案
stdafx.h
是 Visual Studio 使用的预编译头文件,您不需要它。- 您似乎错过了
int main()
函数 - 它是
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/