摘要:
如果容器中是类,如果要调用sort则需要重载操作符 "<" 包含头文件 1 #define _CRT_SECURE_NO_WARNINGS 2 #include <vector> 3 #include <list> 4 #include <algorithm> 5 #include <iostrea 阅读全文
摘要:
1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 //拷贝数据,与反向拷贝 10 { 11 vector myint{ 1,2,3,4,5 }; 12 list myli... 阅读全文
摘要:
#include <algorithm> 算法 常用版本 描述 返回Type std::find() find(_InIt _Fisrt,_InIt _Last, _Ty& _Val); 从两个迭代器指定的范围中查找指定值 引用被查找的值的iterator或end() std::find_if() 阅读全文
摘要:
1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 vector myint{ 1,2,3,4,5 }; 10 list mylist{ 10,9,7,6,5 }; 11 //copy不能自动拓展,需要被拷贝的有足够的... 阅读全文
摘要:
对容器进行填充 1 void show(int x) 2 { 3 cout << x << endl; 4 } 1 int a[10]; 2 //指定一个数据开始,对a进行填充 3 iota(a, a + 10, 1); 4 5 for_each(a, a + 10, show); 容器两个元素进行 阅读全文
摘要:
通过仿函数for_each操作 1 vector<int> myv{ 1,2,3,4,5 }; 2 list<double> db{ 1.1,2.2,3.3,4.4,5.5 }; 3 4 //循环算法,算法的泛型 5 print p = for_each(db.begin(), db.end(), 阅读全文
摘要:
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 11 //流迭代器 12 void main1() 13 { 14 //vector v{ 1,2... 阅读全文
摘要:
阅读全文
摘要:
1 #include 2 #include 3 #include 4 using namespace std; 5 6 7 void main() 8 { 9 unordered_multiset myset{ "pig", "pig", "pig" ,"chicken"}; 10 /*for (auto i : myset) 11 { 12 ... 阅读全文
摘要:
1 #include 2 //老版本的unordered_map(已经废弃不再使用) 3 #include 4 #include 5 using namespace std; 6 7 8 void main() 9 { 10 //允许重复的映射 11 hash_mapmymap{ { "a1",113 },{ "a2",143 },{ "a3",112... 阅读全文