[英]Why does MS Visual Studio #include <stdio.h> in stdafx.h by default?
MS Visual Studio 2017, new Windows Console Application project from VisualC++ category. MS Visual Studio 2017,VisualC ++类别中的新Windows控制台应用程序项目。 The default
stdafx.h
header includes the following lines: 默认的
stdafx.h
标头包含以下几行:
#include <stdio.h>
#include <tchar.h>
And below them: 在它们下面:
// TODO: reference additional headers your program requires here
Because this comment is put below, not above #include <stdio.h>
, I am inclined to believe that stdio.h
is included by default not as a convenience for the user who would probably #include
it anyway, but is for some reason required? 因为此注释放在下面,而不是在
#include <stdio.h>
之上,所以我倾向于认为默认情况下包括stdio.h
并不是为了方便可能会#include
它的用户使用,但是出于某种原因需要? The fact that stdio.h
is included rather than cstdio
only seems to support this interpretation? 包括
stdio.h
而不是cstdio
的事实似乎仅支持这种解释?
AM I right? 我对吗? Can I safely remove
#include <stdio.h>
? 我可以安全地删除
#include <stdio.h>
吗? I'm asking because the very first line in my main
function reads: 我问是因为我
main
功能的第一行显示为:
std::ios_base::sync_with_stdio(false);
Which is obviously incorrect if facilities from stdio
are being used anyway, as this header being included would suggest. 如果仍然使用
stdio
设施,这显然是不正确的,因为包含此标头可能会建议这样做。
1) Can I safely remove the line that says #include <stdio.h>
from stdafx.h
? 1)我可以从
stdafx.h
安全删除表示#include <stdio.h>
的行吗?
2) Can I safely call std::ios_base::sync_with_stdio(false)
? 2)我可以安全地调用
std::ios_base::sync_with_stdio(false)
吗?
3) Is the fact that tchar.h
is also included by default relevant here? 3)此处默认还包含
tchar.h
的事实是否与此相关?
Yes you can remove it. 是的,您可以将其删除。
You can even name your precompiled header not stdafx.h, or disable percompiled header at all. 您甚至可以命名您的预编译头而不是stdafx.h,或者完全禁用预编译头。
It is just convenience and example to start with. 首先只是方便和示例。
Its up to you if you want to use it, however before removing it read on this MSDN about precompiled Header Files 如果您要使用它,则取决于您,但是在删除它之前,请在此MSDN上阅读有关预编译的头文件的信息。
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.