C++ cstdlib Library
C++ cstdlib Functions
The <cstdlib> library has many useful functions, for example to convert text to numbers, create random numbers, and stop the program.
The table below lists the most common <cstdlib> functions.
| Function | Description |
|---|---|
| abs() | Returns the absolute (positive) value of a whole number |
| atof() | Converts the number at the start of a C-style string to a double |
| atoi() | Converts the number at the start of a C-style string to an int |
| atol() | Converts the number at the start of a C-style string to a long |
| div() | Divides two whole numbers, and returns both the quotient and the remainder |
| exit() | Stops the program right away |
| rand() | Returns a random whole number |
| srand() | Sets the starting value (seed) for rand() |
Related Pages
C++ How To Generate a Random Number
C++ Convert Strings and Numbers