206 lines
4.4 KiB
Markdown
206 lines
4.4 KiB
Markdown
|
||
C++标准库提供了丰富的头文件,用于包含各种功能和数据结构。以下是一些常用的C++标准库头文件及其主要作用:
|
||
|
||
1. **iostream**:输入和输出流操作,包括`cin`、`cout`、`cerr`、`clog`等。
|
||
|
||
cppCopy code
|
||
|
||
`#include <iostream>`
|
||
|
||
2. **iomanip**:输入输出流格式化操作,如`setw`、`setprecision`等。
|
||
|
||
cppCopy code
|
||
|
||
`#include <iomanip>`
|
||
|
||
3. **fstream**:文件输入和输出流操作,用于文件的读写。
|
||
|
||
cppCopy code
|
||
|
||
`#include <fstream>`
|
||
|
||
4. **string**:字符串操作,提供了丰富的字符串处理函数和类。
|
||
|
||
cppCopy code
|
||
|
||
`#include <string>`
|
||
|
||
5. **vector**:动态数组,提供了可变大小的数组容器。
|
||
|
||
cppCopy code
|
||
|
||
`#include <vector>`
|
||
|
||
6. **list**:双向链表容器。
|
||
|
||
cppCopy code
|
||
|
||
`#include <list>`
|
||
|
||
7. **deque**:双端队列容器。
|
||
|
||
cppCopy code
|
||
|
||
`#include <deque>`
|
||
|
||
8. **queue**:队列容器,通常基于deque实现。
|
||
|
||
cppCopy code
|
||
|
||
`#include <queue>`
|
||
|
||
9. **stack**:栈容器,通常基于deque实现。
|
||
|
||
cppCopy code
|
||
|
||
`#include <stack>`
|
||
|
||
10. **map**:关联容器,实现键-值对的有序映射。
|
||
|
||
cppCopy code
|
||
|
||
`#include <map>`
|
||
|
||
11. **set**:关联容器,实现有序集合。
|
||
|
||
cppCopy code
|
||
|
||
`#include <set>`
|
||
|
||
12. **algorithm**:提供了各种常见算法,如排序、查找等。
|
||
|
||
cppCopy code
|
||
|
||
`#include <algorithm>`
|
||
|
||
13. **numeric**:数值算法,提供了一些对数值进行操作的函数。
|
||
|
||
cppCopy code
|
||
|
||
`#include <numeric>`
|
||
|
||
14. **cmath**:数学函数库,提供了数学运算函数。
|
||
|
||
cppCopy code
|
||
|
||
`#include <cmath>`
|
||
|
||
15. **ctime**:时间和日期操作,提供了与时间相关的函数。
|
||
|
||
cppCopy code
|
||
|
||
`#include <ctime>`
|
||
|
||
16. **cstdlib**:通用工具函数,提供了一些通用的功能,如`atoi`、`rand`等。
|
||
|
||
cppCopy code
|
||
|
||
`#include <cstdlib>`
|
||
|
||
17. **cassert**:断言,用于在程序中插入调试断言。
|
||
|
||
cppCopy code
|
||
|
||
`#include <cassert>`C++标准库提供了丰富的头文件,用于包含各种功能和数据结构。以下是一些常用的C++标准库头文件及其主要作用:
|
||
|
||
1. **iostream**:输入和输出流操作,包括`cin`、`cout`、`cerr`、`clog`等。
|
||
|
||
cppCopy code
|
||
|
||
`#include <iostream>`
|
||
|
||
2. **iomanip**:输入输出流格式化操作,如`setw`、`setprecision`等。
|
||
|
||
cppCopy code
|
||
|
||
`#include <iomanip>`
|
||
|
||
3. **fstream**:文件输入和输出流操作,用于文件的读写。
|
||
|
||
cppCopy code
|
||
|
||
`#include <fstream>`
|
||
|
||
4. **string**:字符串操作,提供了丰富的字符串处理函数和类。
|
||
|
||
cppCopy code
|
||
|
||
`#include <string>`
|
||
|
||
5. **vector**:动态数组,提供了可变大小的数组容器。
|
||
|
||
cppCopy code
|
||
|
||
`#include <vector>`
|
||
|
||
6. **list**:双向链表容器。
|
||
|
||
cppCopy code
|
||
|
||
`#include <list>`
|
||
|
||
7. **deque**:双端队列容器。
|
||
|
||
cppCopy code
|
||
|
||
`#include <deque>`
|
||
|
||
8. **queue**:队列容器,通常基于deque实现。
|
||
|
||
cppCopy code
|
||
|
||
`#include <queue>`
|
||
|
||
9. **stack**:栈容器,通常基于deque实现。
|
||
|
||
cppCopy code
|
||
|
||
`#include <stack>`
|
||
|
||
10. **map**:关联容器,实现键-值对的有序映射。
|
||
|
||
cppCopy code
|
||
|
||
`#include <map>`
|
||
|
||
11. **set**:关联容器,实现有序集合。
|
||
|
||
cppCopy code
|
||
|
||
`#include <set>`
|
||
|
||
12. **algorithm**:提供了各种常见算法,如排序、查找等。
|
||
|
||
cppCopy code
|
||
|
||
`#include <algorithm>`
|
||
|
||
13. **numeric**:数值算法,提供了一些对数值进行操作的函数。
|
||
|
||
cppCopy code
|
||
|
||
`#include <numeric>`
|
||
|
||
14. **cmath**:数学函数库,提供了数学运算函数。
|
||
|
||
cppCopy code
|
||
|
||
`#include <cmath>`
|
||
|
||
15. **ctime**:时间和日期操作,提供了与时间相关的函数。
|
||
|
||
cppCopy code
|
||
|
||
`#include <ctime>`
|
||
|
||
16. **cstdlib**:通用工具函数,提供了一些通用的功能,如`atoi`、`rand`等。
|
||
|
||
cppCopy code
|
||
|
||
`#include <cstdlib>`
|
||
|
||
17. **cassert**:断言,用于在程序中插入调试断言。
|
||
|
||
cppCopy code
|
||
|
||
`#include <cassert>` |