名稱空間
變體
操作

標準庫標頭檔案 <cstdlib>

來自 cppreference.com
 
 
標準庫標頭檔案
演算法
<algorithm>
<numeric>
字串
<cctype>
<cstring>
<cuchar> (C++11)
<cwchar>
<cwctype>
<string_view> (C++17)
<string>
文字處理
<clocale>
<codecvt> (C++11/17/26*)
<locale>
<regex> (C++11)
<text_encoding> (C++26)   
數值
<cfenv> (C++11)
<cmath>
<complex>
<linalg> (C++26)
<numbers> (C++20)
<random> (C++11)
<simd> (C++26)
<valarray>
時間
<chrono> (C++11)
<ctime>
C 相容性
<ccomplex> (C++11/17/20*)
<ciso646> (until C++20)
<cstdalign> (C++11/17/20*)
<cstdbool> (C++11/17/20*)
<ctgmath> (C++11/17/20*)
 

此標頭檔案最初是 C 標準庫中的 <stdlib.h>

此標頭檔案提供各種實用程式。在此處定義的符號被多個庫元件使用。

目錄

型別

結構體型別,由 std::div 返回
(typedef) [編輯]
結構體型別,由 std::ldiv 返回
(typedef) [編輯]
(C++11)
結構體型別,由 std::lldiv 返回
(typedef) [編輯]
sizeof 運算子返回的無符號整型
(typedef) [編輯]

宏常量

指示程式執行狀態
(宏常量) [編輯]
MB_CUR_MAX
當前區域設定下多位元組字元的最大位元組數
(宏常量) [編輯]
實現定義的空指標常量
(宏常量) [編輯]
std::rand 生成的最大可能值
(宏常量) [編輯]

函式

程序控制
導致程式異常終止(不進行清理)
(函式) [編輯]
導致程式正常終止並進行清理
(函式) [編輯]
導致程式快速終止而不完全清理
(函式) [編輯]
(C++11)
導致程式正常終止而不進行清理
(函式) [編輯]
註冊一個函式,在呼叫 std::exit() 時被呼叫
(函式) [編輯]
註冊一個函式,在呼叫 std::quick_exit 時被呼叫
(函式) [編輯]
呼叫宿主環境的命令處理器
(函式) [編輯]
訪問環境變數列表
(函式) [編輯]
記憶體管理
分配記憶體
(函式) [編輯]
分配對齊記憶體
(函式) [編輯]
分配並清零記憶體
(函式) [編輯]
擴充套件或收縮先前分配的記憶體塊
(函式) [編輯]
釋放先前分配的記憶體
(函式) [編輯]
數字字串轉換
將位元組字串轉換為浮點值
(函式) [編輯]
將位元組字串轉換為整數值
(函式) [編輯]
將位元組字串轉換為整數值
(函式) [編輯]
將位元組字串轉換為無符號整數值
(函式) [編輯]
將位元組字串轉換為浮點值
(函式) [編輯]
寬字串操作
返回下一個多位元組字元的位元組數
(函式) [編輯]
將下一個多位元組字元轉換為寬字元
(函式) [編輯]
將寬字元轉換為其多位元組表示
(函式) [編輯]
將窄多位元組字元字串轉換為寬字串
(函式) [編輯]
將寬字串轉換為窄多位元組字元字串
(函式) [編輯]
雜項演算法和數學
生成偽隨機數
(函式) [編輯]
為偽隨機數生成器播種
(函式) [編輯]
對未指定型別的元素範圍進行排序
(函式) [編輯]
在陣列中搜索未指定型別的元素
(函式) [編輯]
計算整數值的絕對值 (|x|)
(函式) [編輯]
計算整數除法的商和餘數
(函式) [編輯]

[編輯] 概要

namespace std {
  using size_t =  /* see description */; // freestanding
  using div_t =   /* see description */; // freestanding
  using ldiv_t =  /* see description */; // freestanding
  using 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 aliases
  extern "C" using /* c-atexit-handler */ = void(); // exposition only
  extern "C++" using /* atexit-handler */ = void(); // exposition only
  extern "C" using /* c-compare-pred */ =           // exposition only
    int(const void*, const void*);
  extern "C++" using /* compare-pred */ =           // exposition only
    int(const void*, const void*);
 
  // start and termination
  [[noreturn]] void abort() noexcept;                       // freestanding
  int atexit(/* c-atexit-handler */* func) noexcept;        // freestanding
  int atexit(/* atexit-handler */* func) noexcept;          // freestanding
  int at_quick_exit(/* c-atexit-handler */* func) noexcept; // freestanding
  int 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(const char* name);
  int system(const char* string);
 
  // C library memory allocation
  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);
 
  // multibyte / wide string and character conversion functions
  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 standard library algorithms
  void* bsearch(const void* key, const void* base,  // freestanding
                size_t nmemb, size_t size, /* c-compare-pred */* compar);
  void* bsearch(const void* key, const void* 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 generation
  int rand();
  void srand(unsigned int seed);
 
  // absolute values
  constexpr int abs(int j);                       // freestanding
  constexpr long int abs(long int j);             // freestanding
  constexpr long long int abs(long long int j);   // freestanding
  constexpr /* floating-point-type */
    abs(/* floating-point-type */ j);             // freestanding-deleted
 
  constexpr long int labs(long int j);            // freestanding
  constexpr long long int llabs(long long int j); // freestanding
 
  constexpr div_t div(int numer, int denom);                         // freestanding
  constexpr ldiv_t div(long int numer, long int denom);              // freestanding
  constexpr lldiv_t div(long long int numer, long long int denom);   // freestanding
  constexpr ldiv_t ldiv(long int numer, long int denom);             // freestanding
  constexpr lldiv_t lldiv(long long int numer, long long int denom); // freestanding
}

[編輯] 缺陷報告

下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。

缺陷報告 應用於 釋出時的行為 正確的行為
LWG 286 C++98 <cstdlib> 中沒有提供 size_t 的定義 已提供

[編輯] 另請參閱