Standard library header <cstdlib>
From cppreference.com
This header was originally in the C standard library as <stdlib.h>.
This header provides miscellaneous utilities. Symbols defined here are used by several library components.
Types | ||
structure type, returned by std::div (typedef) | ||
structure type, returned by std::ldiv (typedef) | ||
(C++11) | structure type, returned by std::lldiv (typedef) | |
unsigned integer type returned by the sizeof operator (typedef) | ||
Macro constants | ||
indicates program execution status (macro constant) | ||
MB_CUR_MAX | maximum number of bytes in a multibyte character with the current locale (macro constant) | |
implementation-defined null pointer constant (macro constant) | ||
maximum possible value generated by std::rand (macro constant) | ||
Functions | ||
Process control | ||
causes abnormal program termination (without cleaning up) (function) | ||
causes normal program termination with cleaning up (function) | ||
(C++11) | causes quick program termination without completely cleaning up (function) | |
(C++11) | causes normal program termination without cleaning up (function) | |
registers a function to be called on std::exit() invocation (function) | ||
(C++11) | registers a function to be called on std::quick_exit invocation (function) | |
calls the host environment's command processor (function) | ||
access to the list of environment variables (function) | ||
Memory management | ||
allocates memory (function) | ||
(C++17) | allocates aligned memory (function) | |
allocates and zeroes memory (function) | ||
expands or shrinks previously allocated memory block (function) | ||
deallocates previously allocated memory (function) | ||
Numeric string conversion | ||
converts a byte string to a floating point value (function) | ||
(C++11) | converts a byte string to an integer value (function) | |
(C++11) | converts a byte string to an integer value (function) | |
(C++11) | converts a byte string to an unsigned integer value (function) | |
converts a byte string to a floating-point value (function) | ||
Wide string manipulation | ||
returns the number of bytes in the next multibyte character (function) | ||
converts the next multibyte character to wide character (function) | ||
converts a wide character to its multibyte representation (function) | ||
converts a narrow multibyte character string to wide string (function) | ||
converts a wide string to narrow multibyte character string (function) | ||
Miscellaneous algorithms and math | ||
generates a pseudo-random number (function) | ||
seeds pseudo-random number generator (function) | ||
sorts a range of elements with unspecified type (function) | ||
searches an array for an element of unspecified type (function) | ||
(C++11) | computes absolute value of an integral value (|x|) (function) | |
(C++11) | computes quotient and remainder of integer division (function) |
[edit]Synopsis
namespace std {using size_t =/* see description */;// freestandingusing div_t =/* see description */;// freestandingusing ldiv_t =/* see description */;// freestandingusing lldiv_t =/* see description */;// freestanding} #define NULL /* see description */ // freestanding#define EXIT_FAILURE /* see description */ // freestanding#define EXIT_SUCCESS /* see description */ // freestanding#define RAND_MAX /* see description */#define MB_CUR_MAX /* see description */ namespace std {// Exposition-only function type aliasesextern"C"using/* c-atexit-handler */=void();// exposition onlyextern"C++"using/* atexit-handler */=void();// exposition onlyextern"C"using/* c-compare-pred */=// exposition onlyint(constvoid*, constvoid*);extern"C++"using/* compare-pred */=// exposition onlyint(constvoid*, constvoid*); // start and termination[[noreturn]]void abort()noexcept;// freestandingint atexit(/* c-atexit-handler */* func)noexcept;// freestandingint atexit(/* atexit-handler */* func)noexcept;// freestandingint at_quick_exit(/* c-atexit-handler */* func)noexcept;// freestandingint at_quick_exit(/* atexit-handler */* func)noexcept;// freestanding[[noreturn]]void exit(int status);// freestanding[[noreturn]]void _Exit(int status)noexcept;// freestanding[[noreturn]]void quick_exit(int status)noexcept;// freestanding char* getenv(constchar* name);int system(constchar* string); // C library memory allocationvoid* aligned_alloc(size_t alignment, size_t size);void* calloc(size_t nmemb, size_t size);void free(void* ptr);void* malloc(size_t size);void* realloc(void* ptr, size_t size); double atof(constchar* nptr);int atoi(constchar* nptr);longint atol(constchar* nptr);longlongint atoll(constchar* nptr);double strtod(constchar* nptr, char** endptr);float strtof(constchar* nptr, char** endptr);longdouble strtold(constchar* nptr, char** endptr);longint strtol(constchar* nptr, char** endptr, int base);longlongint strtoll(constchar* nptr, char** endptr, int base);unsignedlongint strtoul(constchar* nptr, char** endptr, int base);unsignedlonglongint strtoull(constchar* nptr, char** endptr, int base); // multibyte / wide string and character conversion functionsint mblen(constchar* s, size_t n);int mbtowc(wchar_t* pwc, constchar* s, size_t n);int wctomb(char* s, wchar_t wchar); size_t mbstowcs(wchar_t* pwcs, constchar* s, size_t n); size_t wcstombs(char* s, constwchar_t* pwcs, size_t n); // C standard library algorithmsvoid* bsearch(constvoid* key, constvoid* base, // freestanding size_t nmemb, size_t size, /* c-compare-pred */* compar);void* bsearch(constvoid* key, constvoid* base, // freestanding size_t nmemb, size_t size, /* compare-pred */* compar);void qsort(void* base, size_t nmemb, size_t size, // freestanding/* c-compare-pred */* compar);void qsort(void* base, size_t nmemb, size_t size, // freestanding/* compare-pred */* compar); // low-quality random number generationint rand();void srand(unsignedint seed); // absolute valuesconstexprint abs(int j);// freestandingconstexprlongint abs(longint j);// freestandingconstexprlonglongint abs(longlongint j);// freestandingconstexpr/* floating-point-type */ abs(/* floating-point-type */ j);// freestanding-deleted constexprlongint labs(longint j);// freestandingconstexprlonglongint llabs(longlongint j);// freestanding constexpr div_t div(int numer, int denom);// freestandingconstexpr ldiv_t div(longint numer, longint denom);// freestandingconstexpr lldiv_t div(longlongint numer, longlongint denom);// freestandingconstexpr ldiv_t ldiv(longint numer, longint denom);// freestandingconstexpr lldiv_t lldiv(longlongint numer, longlongint denom);// freestanding}
[edit]Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 286 | C++98 | the definition of size_t was not provided in <cstdlib> | provided |