Click to See Complete Forum and Search --> : Simple question on include directives
Erik Wiggins
April 24th, 2003, 11:44 AM
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.
PaulWendt
April 24th, 2003, 11:51 AM
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
Philip Nicoletti
April 24th, 2003, 12:08 PM
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.
PaulWendt
April 24th, 2003, 01:55 PM
Thanks for the correction; I've never read the standard.
Erik Wiggins
April 26th, 2003, 03:01 PM
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++.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.