C++ 无法打开源文件“stdafx.h”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6203266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 19:40:53  来源:igfitidea点击:

cannot open source file "stdafx.h"

c++visual-c++

提问by Jake

I have two include file headers

我有两个包含文件头

#include "stdafx.h"
#include "psapi.h"

However it gives a cannot open source file "stdafx.h" compile time error. I am using Visual Studios 2010. Is "stdafx.h" even necessary? I think so because the program cannot compile if i take it away.

但是它给出了一个无法打开源文件“stdafx.h”的编译时错误。我正在使用 Visual Studios 2010。甚至需要“stdafx.h”吗?我这么认为是因为如果我把它拿走,程序就无法编译。

回答by Vlad

Visual Studio uses it for "precompiled headers" feature. If you are not experienced with Visual Studio, I would recommend to keep the stdafx.h in the project.

Visual Studio 将其用于“预编译头”功能。如果您对 Visual Studio 没有经验,我建议您将 stdafx.h 保留在项目中。

And of course, if you #include it, you ought to have it.

当然,如果你 #include 它,你应该拥有它。

回答by Blazes

stdafx.h is used for precompiled headers. It is not necessary, but disabling the compiler feature can be a little tricky if you have never done it before. If you have it, then you must compile 'stdafx.cpp' before compiling anything else.

stdafx.h 用于预编译头文件。这不是必需的,但如果您以前从未这样做过,禁用编译器功能可能会有点棘手。如果你有它,那么你必须在编译其他任何东西之前编译'stdafx.cpp'。