Why is this so simple code compiled error?

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
User avatar
ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Why is this so simple code compiled error?

Post by ImLazy » Fri Feb 17, 2006 6:17 am

Code: Select all

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int a = -1;
    int b = abs(a);
    cout << b << endl;
    return 0;
}
I stay home. Don't call me out.

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Re: Why is this so simple code compiled error?

Post by sumankar » Fri Feb 17, 2006 6:54 am

ImLazy wrote:

Code: Select all

#include <cmath>
should've been

Code: Select all

#include <cstdlib>
man for abs.

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Re: Why is this so simple code compiled error?

Post by misof » Fri Feb 17, 2006 7:12 am

sumankar wrote:man for abs.
And in case you only have windoze and no man pages, google for "man abs" ;)

User avatar
ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Post by ImLazy » Fri Feb 17, 2006 8:42 am

I don't quite understande what is man page.
At least now I know I should include <cstdlib> instead of <cmath>. Thank you.
I stay home. Don't call me out.

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post by misof » Fri Feb 17, 2006 8:47 am

ImLazy wrote:I don't quite understande what is man page.
At least now I know I should include <cstdlib> instead of <cmath>. Thank you.
"man" is short for manual, this is the standard *NIX way of accessing simple text-based documentation to almost everything. The most common are man pages for programs, but there are also man pages for C functions, system calls, and many other things.

Post Reply

Return to “C++”