Why is this so simple code compiled error?

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

Moderator: Board moderators

Post Reply
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 »

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 »

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 »

sumankar wrote:man for abs.
And in case you only have windoze and no man pages, google for "man abs" ;)
ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Post by ImLazy »

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 »

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++”