简体   繁体   中英

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. The default stdafx.h header includes the following lines:

#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? The fact that stdio.h is included rather than cstdio only seems to support this interpretation?

AM I right? Can I safely remove #include <stdio.h> ? I'm asking because the very first line in my main function reads:

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.

1) Can I safely remove the line that says #include <stdio.h> from stdafx.h ?

2) Can I safely call std::ios_base::sync_with_stdio(false) ?

3) Is the fact that tchar.h is also included by default relevant here?

Yes you can remove it.

You can even name your precompiled header not stdafx.h, or disable percompiled header at all.

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

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM