problem using log in c++

I've been trying to output ln(10) but I get an error. Here is my c++ list:

#include <cmath>
#include <iostream>
using namespace std;

int main()
{
double k;
k = log(10);
cout << k;
}


This is what the error reads as:
1>c:\users\imran\documents\visual studio 2010\projects\testlog\testlog.cpp(8): error C2668: 'log' : ambiguous call to overloaded function
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(575): could be 'long double log(long double)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(527): or 'float log(float)'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\math.h(120): or 'double log(double)'
1> while trying to match the argument list '(int)'


can someone please identify the problem.
It says it doesn't know if it should use the 10 integer as a float, or a double, or long double (because there are three versions of the log() function, overloaded for different types).

Since you store the result in a double type k, it's obvious you want the 10 to be a double.

So try this:
1
2
3
k = log(10.0); // 10 as double
// k = log(10.0f); // 10 as float
// k = log(10.0L); // 10 as long double 


http://www.cplusplus.com/doc/tutorial/constants/
thank you catfish2
This code should work in C++11 because a version of log accepting integer arguments was added.
Topic archived. No new replies allowed.