Why is C++ still using stdio.h?
this is probably a dumb question, but I couldnt find the answer I was looking for. Also, I was unsure if this was a C++ question or a VS2010 question, but the answer I'm looking for is that of a technical POV, so I ended up 开发者_如何学编程here.
When you start a new Console Application project in VS2010, it automatically includes stdafx.h, which in turn includes stdio.h. The answers I found regarding stdio.h vs. iostream was more or less:
stdio.h was used in C and iostream is used in C++
I dont know if this is right or wrong, but...
My question is: Why is stdio.h still automatically included in C++ projects? Wouldnt iostream be sufficient?
IO streams in older C++ implementations were pretty slow, leading programmers to keep using stdio.h
. Apparently, that got included in stdafx.h
in the past and cannot be removed from that header anymore as removing it would break existing code.
Usually projects are created using Create Empty Project
, so that you can customize your includes and precompiled headers yourself.
I have no idea why does this "default" include happens, but it's a good thing to setup your project from scratch as I've described before.
Even if you're using stream output, being able to do some formatting is nice. So, if nothing else, sprintf will sometimes be used. sprintf lives in stdio.h
Possibly because visual studio targets Mort programmers, who wouldn't be able to get 'my first c++' program done without printf, and they would decide that the product didn't work right.
Before down voting plea google visual studio mort persona.
精彩评论