diff --git a/STL/STL-Set/set.cpp b/STL/STL-Set/set.cpp index ebf0c33..b7e2ef4 100644 --- a/STL/STL-Set/set.cpp +++ b/STL/STL-Set/set.cpp @@ -22,6 +22,7 @@ int main(){ cout << endl; cout << a.count(3) << endl; a.erase(6); + //没有.at()和a[i],树结构,不能直接访问第i个,可以it++ for(auto it = a.begin(); it != a.end(); it++){ cout << *it << " "; } diff --git a/STL/STL-map/map.cpp b/STL/STL-map/map.cpp index 222a8fb..9d98733 100644 --- a/STL/STL-map/map.cpp +++ b/STL/STL-map/map.cpp @@ -16,6 +16,7 @@ int main(int argc, char* argv[]){ b.insert(make_pair(3,"333")); b.emplace(make_pair(4,"444")); cout << b.count(3) << endl; + //没有.at()和a[i],树结构,不能直接访问第i个,可以it++ for(auto it = b.begin(); it != b.end(); it++){ cout << it->first << ", " << it->second << " "; } diff --git a/STL/STL-map/multimap.cpp b/STL/STL-map/multimap.cpp new file mode 100644 index 0000000..4ed5852 --- /dev/null +++ b/STL/STL-map/multimap.cpp @@ -0,0 +1,31 @@ +#include +#include +using namespace std; + +bool cmp(int a, int b){ + return a < b; +} + +int main(){ + auto cmpl = [](int a, int b){ + return a > b; + }; + multimap a(cmp); + multimap b(cmpl); + a.insert({{1,"111"},{2,"222"},{1,"11"},{1,"1"},{2,"22"},{3,"333"}});//emplace只能用make_pair,不能直接这么写 + //pair,Key是const修饰的 + for(pair x : a){ + cout << x.first << ", " << x.second << " "; + } + cout << endl; + cout << a.find(1)->second << " " << a.count(1) << endl; + a.erase(a.find(1)); + cout << a.find(1)->second << " " << a.count(1) << endl; + return 0; +} +/* +1, 111 1, 11 1, 1 2, 222 2, 22 3, 333 +111 3 +11 2 +*/ + diff --git a/STL/STL-map/multimap.exe b/STL/STL-map/multimap.exe new file mode 100644 index 0000000..12a5e44 Binary files /dev/null and b/STL/STL-map/multimap.exe differ diff --git a/STL/STL-unordered_map/README.MD b/STL/STL-unordered_map/README.MD new file mode 100644 index 0000000..e69de29 diff --git a/STL/STL-unordered_set/README.MD b/STL/STL-unordered_set/README.MD new file mode 100644 index 0000000..e69de29