CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2002
    Posts
    195

    Simple question on include directives

    Ok I'm fairly new to c++ and I'm trying to learn as much as I can from the ground up. I've got the language down pretty good now I'm tring to learn all of the standerd libraries, what they hold and how to use them. While researching this I have found that some of the librabries avalable are redundant. ie <cmath> ,<math.h> Now I know that the cmath library is newer and simply contains and includes statement for <math.h>. I also know that if you include cmath then you have to use the std:: format in order to be able to use the functions contained in the header file. Where as if you use the include <math.h> method you don't have to do this. So it seems obvious to me that it would be alot easyer to just include the older <math.h>. The only problem I see with this is they most have added the <cmath> header file for a reason so I thuaght I'd come in here and as what the coding standered is for this situatuion before I pick up any more bad habits.

  2. #2
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    Good decision. The <cmath> version is the ONLY version that's
    in the C++ Standard. The <math.h> version was in drafts of the
    standard, but that usage is neither standard nor recommended.
    Get used to the std namespace; namespaces are your friend.

    --Paul

  3. #3
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725
    I agree, use <cmath>.

    However, to be technically accurate, <math.h> , and the
    other "C" headers (such as stdlib.h, stdio.h, wchar.h, etc)
    are still in the standard, but there use is deprecated
    (See section D.5 of the standard).

    The "old C++" headers such as iostream.h are the ones
    that are not in the standard.

  4. #4
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    Thanks for the correction; I've never read the standard.

  5. #5
    Join Date
    Jan 2002
    Posts
    195
    Thank you all for the feed back. Hopefully one day in the next year or so I'll be able to answer people questions about programming in c++.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured