标准库标头 <cstdlib>
来自cppreference.com
此标头原作为 <stdlib.h> 存在于 C 标准库。
此头文件提供杂项工具。此处所定义的各个符号为多个标准库组件所用。
类型 | |
| std::div 返回的结构体类型 (typedef) | |
| std::ldiv 返回的结构体类型 (typedef) | |
(C++11) |
std::lldiv 返回的结构体类型 (typedef) |
| sizeof 运算符返回的无符号整数类型 (typedef) | |
宏常量 | |
| 指示程序执行状态 (宏常量) | |
MB_CUR_MAX |
当前本地环境中多字节字符的最大字节数 (宏常量) |
| 实现定义的空指针常量 (宏常量) | |
| std::rand 生成的最大可能值 (宏常量) | |
函数 | |
进程控制 | |
| 导致非正常的程序终止(不进行清理) (函数) | |
| 导致正常的程序终止并进行清理 (函数) | |
(C++11) |
导致快速程序终止,不进行完全的清理 (函数) |
(C++11) |
导致正常的程序终止,不进行清理 (函数) |
| 注册将于调用 std::exit() 时被调用的函数 (函数) | |
(C++11) |
注册将于调用 quick_exit 时被调用的函数 (函数) |
| 调用宿主环境的命令处理器 (函数) | |
| 访问环境变量列表 (函数) | |
内存管理 | |
| 分配内存 (函数) | |
(C++17) |
分配对齐的内存 (函数) |
| 分配并清零内存 (函数) | |
| 扩张或收缩之前分配的内存块 (函数) | |
| 解分配之前分配的内存 (函数) | |
数值字符串转换 | |
| 转换字节字符串为浮点数 (函数) | |
(C++11) |
转换字节字符串为整数值 (函数) |
(C++11) |
转换字节字符串为整数值 (函数) |
(C++11) |
转换字节字符串为无符号整数值 (函数) |
| 转换字节字符串为浮点值 (函数) | |
宽字符串操纵 | |
| 返回下一个多字节字符中的字节数 (函数) | |
| 转换下一个多字节字符为宽字符 (函数) | |
| 转换宽字符为其多字节表示 (函数) | |
| 转换窄多字节字符串为宽字符串 (函数) | |
| 转换宽字符串为窄多字节字符串 (函数) | |
杂项算法与数学 | |
| 生成伪随机数 (函数) | |
| 初始化伪随机数生成器 (函数) | |
| 对未指定类型的元素范围排序 (函数) | |
| 在未指定类型的数组中搜索元素 (函数) | |
(C++11) |
计算整数的绝对值(|x|) (函数) |
(C++11) |
计算整数除法的商和余数 (函数) |
概要
namespace std {
using size_t = /* 见描述 */; // 独立
using div_t = /* 见描述 */; // 独立
using ldiv_t = /* 见描述 */; // 独立
using lldiv_t = /* 见描述 */; // 独立
}
#define NULL /* 见描述 */ // 独立
#define EXIT_FAILURE /* 见描述 */ // 独立
#define EXIT_SUCCESS /* 见描述 */ // 独立
#define RAND_MAX /* 见描述 */
#define MB_CUR_MAX /* 见描述 */
namespace std {
// 仅用于阐释的函数类型别名
extern "C" using /* C atexit 处理函数 */ = void(); // 仅用于阐述
extern "C++" using /* atexit 处理函数 */ = void(); // 仅用于阐述
extern "C" using /* C 比较谓词 */ = int(const void*, const void*); // 仅用于阐述
extern "C++" using /* 比较谓词 */ = int(const void*, const void*); // 仅用于阐述
// 启动与终止
[[noreturn]] void abort() noexcept; // 独立
int atexit(/* C atexit 处理函数 */* func) noexcept; // 独立
int atexit(/* atexit 处理函数 */* func) noexcept; // 独立
int at_quick_exit(/* C atexit 处理函数 */* func) noexcept; // 独立
int at_quick_exit(/* atexit 处理函数 */* func) noexcept; // 独立
[[noreturn]] void exit(int status); // 独立
[[noreturn]] void _Exit(int status) noexcept; // 独立
[[noreturn]] void quick_exit(int status) noexcept; // 独立
char* getenv(const char* name);
int system(const char* string);
// C 库内存分配
void* 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(const char* nptr);
int atoi(const char* nptr);
long int atol(const char* nptr);
long long int atoll(const char* nptr);
double strtod(const char* nptr, char** endptr);
float strtof(const char* nptr, char** endptr);
long double strtold(const char* nptr, char** endptr);
long int strtol(const char* nptr, char** endptr, int base);
long long int strtoll(const char* nptr, char** endptr, int base);
unsigned long int strtoul(const char* nptr, char** endptr, int base);
unsigned long long int strtoull(const char* nptr, char** endptr, int base);
// 多字节/宽字符串及字符转换函数
int mblen(const char* s, size_t n);
int mbtowc(wchar_t* pwc, const char* s, size_t n);
int wctomb(char* s, wchar_t wchar);
size_t mbstowcs(wchar_t* pwcs, const char* s, size_t n);
size_t wcstombs(char* s, const wchar_t* pwcs, size_t n);
// C 标准库算法
void* bsearch(const void* key, const void* base, // 独立
size_t nmemb, size_t size, /* C 比较谓词 */* compar);
void* bsearch(const void* key, const void* base, // 独立
size_t nmemb, size_t size, /* 比较谓词 */* compar);
void qsort(void* base, size_t nmemb, size_t size, // 独立
/* C 比较谓词 */* compar);
void qsort(void* base, size_t nmemb, size_t size, // 独立
/* 比较谓词 */* compar);
// 低质量随机数生成
int rand();
void srand(unsigned int seed);
// 绝对值
int abs(int j); // 独立
long int abs(long int j); // 独立
long long int abs(long long int j); // 独立
/* 浮点数类型 */ abs(/* 浮点数类型 */ j); // 独立或被删除
long int labs(long int j); // 独立
long long int llabs(long long int j); // 独立
div_t div(int numer, int denom); // 独立
ldiv_t div(long int numer, long int denom); // 独立
lldiv_t div(long long int numer, long long int denom); // 独立
ldiv_t ldiv(long int numer, long int denom); // 独立
lldiv_t lldiv(long long int numer, long long int denom); // 独立
}
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| 缺陷报告 | 应用于 | 出版时的行为 | 正确行为 |
|---|---|---|---|
| LWG 286 | C++98 | <cstdlib> 没有提供 size_t 的定义
|
已提供 |