C++ Standard Library
C++付给你得头文件
Standard Template Library
在标准库中百分之80是STL,标准库>STL,STL有6大部件
标准库以header files形式呈现
- C++标准库得header files 不带副档名(.h) 例如:#include<vector>
- 新式C header files 不带副档名.h 例如: #include<cstdio>
- 旧式C header files(带有副档名 .h)仍可以用 例如#include<stdio.h>
- 所有新式headers内的组件封装于 namespace std
- 旧式的headers内的组件不封装于 namespace std
重要资源网站
- cplusplus.com
- cppreference.com
- gcc.gnu.org
STL体系机构
1.STL组成
STL有六大部件
- 容器(Containers)
- 分配器(Allocators)
- 算法(Algorithms)
- 迭代器(Iterators)
- 适配器(Adapters)
- 仿函数(Functors)
应用场景
2.容器区间
标准库规定使用前闭后开区间来表示元素的区间。
begin()为容器的第一个元素,而end()是容器中最后一个元素的下一个元素
C++ 11提供了新的 range-based for statement
for( decl : coll){
statement
}
for(int i:{2,3,4,5,6}){
std::cout<<i<<std::end;
}
vector<int> vec
for(aotu elem : vec){
cout<<elem<<endl;
}
for( auto& elem : vec){
elem*=3;
}
3.容器的分类
序列式容器(sequence containes)
关联式容器(associative containers):用于大量查找;
不定序容器(unordered containers):C++11 新增的,其实属于关联式容器
下面以缩进的形式表示“基层与衍生层的关系(衍生并非继承,而是复合)
序列式容器
- array:连续空间 since C++ 11
- vector: 连续空间
- heap:以算法形式呈现
- priority_queue
- list:双向
- slist:单向,非标准
- deque:分段连续空间
- stack: container adapter容器适配器
- queue: container adapter容器适配器
关联式容器
- rb_tree 非公开
- set
- map
- multiset
- multimap
- hashtable 非公开
- hash_set 非标准
- hash_map 非标准
- hash_multiset 非标准
- hash_multimap 非标准
注:C++ 11中,slist名为forward_list,hash_set,hash_map名为unordered_set,unordered_map.....
相关预备知识
1.函数重载
之前写过一篇非常详细的C++中函数重载的博客,直接发个传送门
https://blog.csdn.net/weixin_39568744/article/details/105329524
2.泛型编程
之前写过一篇非常详细的C++中泛型编程的博客,直接发个传送门
https://blog.csdn.net/weixin_39568744/article/details/105950208