c++编程之标准库和STL
1. C++标准库
C++提供了很多库:
- 标准 ANSI C 库都可以移植到 C++中。不同于 ANSI C 库的是,C++中需要在库名前加上"c"前缀,而且去掉".h",例如
<cmath>对应于 C 语言就是<math.h>,<cstdlib>对应于 C 语言的<stlib.h> - C++新增的库,例如
<iostream>,<iomanip>,<string>,<fstream>,<sstream> - C++STL:包括容器,迭代器,算法和函数对象
- Boost C++库
1.1 C 库和相关头文件
<cstring>:待会解释<cmath>:数学计算相关的库<cstdlib>:通用工具,例如异常(abort, exit, EXIT_SUCCESS, EXIT_FAILURE);环境相关(getenv);动态内存管理(malloc, free, calloc, realloc),字符解析(atoi, atof, atol, strtod), 伪随机序列生成(rand, srand, RAND_MAX);数组搜索和排序(bsearch, qsort)<cctype>:字符类型检测(isalpha, isdigit, isalnum, isspace, isupper, islower, isblank, iscntrl, isgraph, isprint, ispunct, isxdigit)和字符转换(toupper, tolower)<climits>,<cfloat>:Size and limit of integer types (INT_MAX, INT_MIN, UINT_MAX, CHAR_BIT; and SHRT_XXX for short, LONG_XXX for long, LLONG_XXX for long long, CHAR_XXX for char) and floating-point types (DBL_MIN, DBL_MAX, DBL_DIG, DBL_MIN_EXP, DBL_MAX_EXP; and FLT_XXX for float, LDBL_XXX for long double)<ctime>:time, difftime, clock, gmttime, localtime, and etc.<cstdio>: C’s IO operations (scanf, printf, fscanf, fprintf, fopen, fclose, etc)<cassert>,<cerrno>,csignal>: 断言和错误<clocale>:本地化<cstdbool>,<cstdint>,<cstddef>,<cstdarg>:<cuchar>,<cwchar>,<cwcchar>: Unicode 字符
1.2 C++库和相关头文件
<ios>, <iostream>, <istream>, <ostream>, <fstream>, <sstream><iomanip><string><regex><random><limits><stdexception>, <exception><complex>, <tuple>, <valarry><locale><typeinfo><chrono>- 其它:
<codecvt>, <new>, <ratio>, <system_error>, <type_traits>
1.3 C++ STL 和相关头文件
STL 主要由以下头文件提供:




