When using abs() it shows "abs is ambiguous" but when I try it on another editor it works

Viewed 835

In my code abs() isnt working but when put in a different code editor it does work. I dont know what to do. Cant find answers anywhere. Please help. Error: ("abs" is ambiguousC/C++(266))

#include <iostream>
#include <cstdlib>

using namespace std;

int main(){

    int x = -1;
    int a = abs(x);

    cout<< a;

}
2 Answers

More information will be helpful. There's no need to add "using namespace std" here. You can try to modify "int a = abs(x);" ==> "int a = ::abs(x);"

#include <iostream>
#include <cstdlib>

using namespace std;

int main(){

    int x = -1;
    int a = fabs(x);

    cout<< a;

}

or


#include <iostream>
#include <stdlib.h>


int main() {

    int x = -1;
    int a = abs(x);

    std::cout << a;

}

Related