簡體   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,VisualC ++類別中的新Windows控制台應用程序項目。 默認的stdafx.h標頭包含以下幾行:

#include <stdio.h>
#include <tchar.h>

在它們下面:

// TODO: reference additional headers your program requires here

因為此注釋放在下面,而不是在#include <stdio.h>之上,所以我傾向於認為默認情況下包括stdio.h並不是為了方便可能會#include它的用戶使用,但是出於某種原因需要? 包括stdio.h而不是cstdio的事實似乎僅支持這種解釋?

我對嗎? 我可以安全地刪除#include <stdio.h>嗎? 我問是因為我main功能的第一行顯示為:

std::ios_base::sync_with_stdio(false);

如果仍然使用stdio設施,這顯然是不正確的,因為包含此標頭可能會建議這樣做。

1)我可以從stdafx.h安全刪除表示#include <stdio.h>的行嗎?

2)我可以安全地調用std::ios_base::sync_with_stdio(false)嗎?

3)此處默認還包含tchar.h的事實是否與此相關?

是的,您可以將其刪除。

您甚至可以命名您的預編譯頭而不是stdafx.h,或者完全禁用預編譯頭。

首先只是方便和示例。

如果您要使用它,則取決於您,但是在刪除它之前,請在此MSDN上閱讀有關預編譯的頭文件的信息。

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM