gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 18:20:10 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com