Im needing the natural logarithm function for use in a .cpp (c++) source file. Now, of course I can do this with a quick google search and a simple library solution. But Im a bit confused...
On the cplusplus dot com website under reference/cmath/log/ they have an example of how to use the log function, as follows
/* log example */
#include <stdio.h> /* printf */
#include <math.h> /* log */
int main ()
{
double param, result;
param = 5.5;
result = log (param);
printf ("log(%f) = %fn", param, result );
return 0;
}
some questions i have:
1) Why are they using
<stdio.h>
I thought this was for C and not really for C++ ?
2) Why are they using
<math.h>
I though the .h represented C header files rather than the .hpp C++ header files?
Forgetting about the use of stdio (i'll use iostream anyway) but even so by using
<math.h>
It feels like I'm writing C code and not C++ code. Im learning C++ through a taught course and the instructor covered C in the first week and then said we wont be using C again but will be using C++ from now on. I feel like I wont be able to explain myself if the teacher asks "why did you use a C header file? You are supposed to be working in C++".
Any explanations much appreciated.
Aucun commentaire:
Enregistrer un commentaire