【C++语法】STL
Container
Built-in Types | Abstract Data Types |
---|---|
defined directly by C++ language | defined by standard libraty |
repersents computer hardware facilities | usually don't implemented by computer hardware |
e.g., int, array... | e.g., vector, string... |
graph LR;
A(Containers)-->B(第一类容器)
B-->D(Sequential Containers)
D-->vector
D-->list/forward_list
D-->deque
B-->E(Associative Containers 红黑树-自排序)
E-->set/multiset
E-->map/multimap
B-->G(Unordered Associative Containers 哈希表-读取快)
G-->unordered_set
G-->unordered_map
A(Containers)-->C(第二类容器)
C-->F(Adaptors)
F-->stack
F-->queue/priority_queue
String
std::string::npos //-1
/*初始化*/
string s(10, 'c'); //s: "cccccccccc"
/*遍历*/
for(auto &c:s) //&引用
/*normal*/
s.size(); s.empty();
/*find*/
s.find(substr, pos=0); //return size_type
/*子串*/
s.substr(pos,count); //return string
/*string, char [], char**/
...
/*string,int*/
to_string((int)i); //<string>
/*Algorithms*/
reverse(s.begin(),s.end());
1. vector
/*Algorithms*/
vector<int>::iterator max = max_element(v.begin(),v.end());
reverse(v.begin(),v.end());
sort(v.begin(),v.end(),cmp()=NULL);
stable_sort(v.begin(),v.end(),cmp()=NULL);
from Chu