absolute value for long long it

How to obtain absolute value for an "long long int" n gcc-4.8.2

The following code facing compilation error , i used llabs(x) too , how to get rid out of that ?

Thanks in advance :)

1
2
3
4
5
6
7
8
9
10
11
12
   #include<iostream>
#include<cmath>

using namespace std;

int main() {
    long long int x;

    cin >> x;
    cout << abs(x);
    return 0;
}
Following is compilation error

In function 'int main()':
error: call of overloaded 'abs(long long int&)' is ambiguous
It works for me with MinGW GCC 4.8.1 32-bit.

Maybe try #include <cstdlib>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
// #include <cmath>
#include <cstdlib>

using namespace std;

int main() 
{
    long long int x;

    cin >> x;
    cout << abs(x);
    return 0;
}


http://www.cplusplus.com/reference/cstdlib/abs/
Last edited on
Thanks @chervil
Topic archived. No new replies allowed.