Are they the same
Are they the same
Yes and no?
I don't know exactly how it goes, but it's something like this: When the C99 standard came out, all the old C libraries were changed from the .h suffix to the 'c' prefix. math.h became cmath, stdio.h became cstdio, string.h became cstring... etc. They were also defined under the std namespace, which is why you use that namespace in your programs.
I'm sure there is a C history buff that'd be willing to break it down in better detail (or completely rebut what I just told you. )
Sent from my iPadŽ
I just searched the site and found an answer to that (amazing, the things you can find when you search the site). "math.h" is the header file with functions and such that has been used since C. "cmath.h" is the same, but for C++. I don't know if there are differences other than that, though (I didn't even know cmath existed before I read this).
Not quite. <cmath> is a C++ headerr provides the same functionality as the C header named <math.h>, but everything in it lives in namespace std.
There is no such thing as cmath.h. Read my post.Originally Posted by KingDubya
Sent from my iPadŽ
Meh, I always include header files using a ".h" at the end. It still works.Originally Posted by SlyMaelstrom
In C++, both <math.h> and <cmath> are allowed (both are standard). However, you should prefer using the C++ version, <cmath>. The C version was deprecated by the C++ standard (C99 is different, you meant the one and only C++ standard from 1998). Deprecated just means it is allowed, but might be removed from the standard in the future, so you should prefer the alternative.
>> Meh, I always include header files using a ".h" at the end. It still works.
It is wrong and probably only "works" in some cases if you are lucky. Use cmath or math.h, cmath.h makes no sense.
Well, since I've never used cmath before (refer to my first post in this thread), I've never experienced that. I don't think I've really ever used any that have the "c" prefix in any of my programs really. If that seems a little amateur-ish, I must let you know that I've only taken one year of C++ at my high school so far, and even then we had a teacher who was farther behind in programming than me by the end of the year; that and we had a really old textbook that spoke about libraries our compiler didn't have (for one, we didn't have "string.h").Originally Posted by Daved
Last edited by KingDubya; 12-02-2005 at 03:44 PM.
The reason your probably using math.h and iostream.h is because highschools are cheap and you're probably still using Turbo C++ which doesn't have the modern libraries.
Just soak in the knowledge as we explain it, though.
Sent from my iPadŽ
In Visual Studio .NET 2003, <cmath> includes math.h, then adds a lot of using statements like this one:
using ::abs; using ::acos; using ::asin;
>> If that seems a little amateur-ish
I was referring to cmath.h which was probably just a typo where you meant math.h. Using math.h is not amateurish, it is just becoming out of date for C++ programmers.