Why is map imported as #include <map>, but stdio imported as #include <stdio.h>?
Why is map imported as #include <map> , but stdio imported as #include <stdio.h>
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
All standard C++ headers don’t want the
.hin the end. I read somewhere that the concept is that they don’t need to be actual files,even if I never saw an implementation do it in another manneredit: actually the compiler intrinsics should work considering the headers included but not actually including them as files; see @Yttrill‘s comment.For the
stdio.hthing, in a C++ application you shouldn’t include<stdio.h>, but you should instead include<cstdio>. In general, you shouldn’t include the “normal” C headers, but their C++-ized counterparts, which haven’t got the.hin the end, have acin front and put all the symbols defined in them in thestdnamespace. So,<math.h>becomes<cmath>,<stdlib.h>becomes<cstdlib>, and so on.In general, you should use the C++-ized versions of C headers both to avoid to pollute the global namespace (assuming you’re not one of those guys who put
using namespace std;everywhere) and to benefit of some C++ improvements to the standard C headers (e.g. added overloading to some math functions).In general, the implementation of this whole thing is simply done by having such files without extension in the directory in which the compiler looks for the header files. In my g++ 4.4 installation, for example, you have:
The C++-ized C headers in theory could just be a
but in general they are more complicated to deal with implementation-specific problems (especially regarding macros) and to add C++-related functionality (see e.g. the previous example of added overloads in
<cmath>).By the way, the C++ standard (§D.5) do not say that the
<c***>headers should behave as if they included the<***.h>headers in anamespace stddirective, but the opposite:Notice that such headers are considered deprecated (§C.2.1), so this is the main reason you shouldn’t use them: