简体   繁体   English

为什么MS Visual Studio #include <stdio.h> 默认情况下在stdafx.h中?

[英]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.

相关问题 Visual Studio-为什么要嵌入stdafx.h - Visual Studio - why does stdafx.h gets embedded 为什么我必须在Microsoft Visual Studio C ++应用程序中#include“ stdafx.h”? - Why do i have to #include “stdafx.h” in Microsoft visual studio c++ applications? 为什么必须在开始时强制包含stdafx.h? - Why mandatory to include stdafx.h at the start? 为什么Visual Studio C ++甚至在不需要的文件上也要求包含“ StdAfx.h”? - Why does Visual Studio C++ require including “StdAfx.h” even on files that don't need it? 为什么我们使用`#include“stdafx.h”`而不是`#include <stdafx.h> `? - Why do we use `#include “stdafx.h”` instead of `#include <stdafx.h>`? Visual Studio 2017会不断重新编译stdafx.h吗? - Visual Studio 2017 keeps recompiling stdafx.h needlessly? 为什么不包含 stdafx.h 对 VisualStudio 来说还不够? - Why isn't include stdafx.h not enough for VisualStudio? 我可以使用#include“pch.h”而不是#include“stdafx.h”作为Visual Studio C ++中的预编译头吗? - Can I use #include “pch.h” instead of #include “stdafx.h” as my precompile header in Visual Studio C++? 为什么stdafx.h的运行方式如何呢? - Why does stdafx.h work the way it does? 包括其他项目中的stdafx.h - Include the stdafx.h from other projects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM