[Visual Studio] stdio.h?

Well I decided to get into C++ because it seemed like a fun project over the summer, and in the tutorials whilst using the hello world program example, it would not work because I had not included stdio.h. After using google I found out how to disable stdio.h so I could just use iostream. But what is stdio.h and what does it do? What are the negatives of disabling it?

I meant stdafx.h! Sorry!
Last edited on
<stdio.h> is a C header for I/O. It has things like printf, scanf, fopen, etc.

<cstdio> is the equivilent C++ header which has the same things.

<iostream> is another C++ header which has cout, cin, and other things. It uses a different type of I/O than cstdio which revolves around the concept of a 'stream' rather than a 'file'.


The two headers are very similar. Their main differences are in style and typesafety. iostream is more C++-ish whereas cstdio is more C-ish. iostream tends to be more typesafe and more verbose, whereas cstdio tends to be more succinct.
Thanks for the fast answer! But the thing is, it was preventing me from running a simple hello world program.

I meant stdafx.h btw, sorry! But yes, what does stdafx.h do and why did it prevent me from using my hello world program at first?
Last edited on
Generally if you see a "C++" tutorial that uses stdio.h/cstdio and friends, run away.
There's a big difference between stdafx.h and stdio.h. stdafx.h is a header used by VS if you've enabled precompiled headers (default setting for Windows applications).
Yes I realize the mistake I made in the title now, but is stdafx.h any good and what does it do/change?
Thank you! But I still am not sure why it would let me use my hello world program.
Last edited on
If your project is set to use precompiled headers, then you typically MUST include stdafx.h and will get an error if you don't.

If your project is not set to use precompiled headers, then stdafx.h likely doesn't exist and you will get an error if you try to include it.



It all depends on how you set up your project.


Personally, I always select the "empty project" option from the VS project screen. But if you select any of the others, it's likely that it will enable precompiled headers by default.
Thanks!
Topic archived. No new replies allowed.