【发布时间】:2018-04-12 20:56:22
【问题描述】:
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 也包含在此处是否相关?
【问题讨论】:
-
它只是一个帮助启动新项目的模板文件。修复它以方便您。该模板的质量值得商榷。
-
这可能是因为几十年来没有人更新过该模板...
TCHAR也很老派,因为现代应用程序应该只使用 Unicode——上一次 ANSI 真正重要的是 Windows 95。然而,大多数人可能在他们的控制台应用程序中使用printf或wprintf。
标签: c++ visual-studio visual-c++ stdafx.h