CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Header files

  1. #1
    Join Date
    Aug 2009

    Header files


    What is the difference between the header files <header.h> and <header>?

    I know that the <...> brackets indicate that the header file is located in some standard directory that the compiler can access, but why do some of these have the ".h", and some do not?

    For example, I am using some mathematical functions from <cmath> in Visual Studio, which seem to be the same as with <math.h>.


  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Seattle, WA

    Re: Header files

    In some cases, C header files like <math.h> have a different name in C++. So <cmath> is the C++ version of <math.h>, <cstdio> is the C++ name of C's <stdio.h>, etc. There may or may not be an actual difference in the content of the files, it's just good practice to select the right header for the language you're using.

    In certain other cases, both standard and pre-standard versions of a header may be available. Some compilers still support <iostream.h>, a pre-standard header (which is still encouraged by a depressingly large number of tutorials), but the correct standard header is <iostream> and has been for years. Don't use pre-standard headers, as a rule.

    There's at least one potentially confusing case. The C header <string.h> is available to C++ as <cstring>, but C++ *also* provides a <string> header, which contains the std::string class. So <cstring> and <string> are very different headers, but one of them is almost the same as <string.h>. Also note that the MFC class "CString" is not associated with any of these standard headers.
    Last edited by Lindley; March 15th, 2011 at 04:18 PM.

  3. #3
    Join Date
    Aug 2009

    Re: Header files

    It's a naming convention: C++ standard libraries header files don't have the .h extension and also the C standard libraries are named with c prefix and without extension (usually old names like math.h are still accessible).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.