D
D
Dmitry Yutkin2014-09-20 22:23:33
C++ / C#
Dmitry Yutkin, 2014-09-20 22:23:33

How to fix C++ compiler errors?

I can't figure out what the compiler on acmp.ru wants. Where is the mistake? gcc on os x compiles fine. The code:

#include <fstream>
#include <cmath>

using namespace std;
int main(int argc, char* argv[]) {
  ifstream fIn("input.txt");
  ofstream fOut("output.txt");
  double n = 0;
  fIn >> n;
  fOut << (log(n) / log(2) == floor(log(n) / log(2)) ? "YES" : "NO");
  return 0;
}

Errors:
task.cpp
task.cpp(10) : error C2668: 'log' : ambiguous call to overloaded function
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(612): could be 'long 
double log(long double)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(564): or       'float log
(float)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(193): or       'double log
(double)'
        while trying to match the argument list '(int)'
task.cpp(10) : error C2668: 'log' : ambiguous call to overloaded function
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(612): could be 'long 
double log(long double)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(564): or       'float log
(float)'
        C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\math.h(193): or       'double log
(double)'
        while trying to match the argument list '(int)'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav, 2014-09-20
@Nirail

The log function does not take an integer argument, you must explicitly convert to one of the following: long double, double, float.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question