map_set
来源:互联网 发布:怎么查看当前linux版本 编辑:程序博客网 时间:2024/05/18 00:51
#pragma once
//#include <set>
//
//void test_set()
//{
// typedef set<int>::iterator SetIter;
// set<int> s1;
// s1.insert(1);
// //s1.insert(3);
// s1.insert(1);
// s1.insert(5);
// s1.insert(7);
// s1.insert(2);
// s1.insert(4);
//
// set<int>::iterator it1 = s1.begin();
// while (it1 != s1.end())
// {
// cout<<*it1<<" ";
// ++it1;
// }
// cout<<endl;
//
// set<int>::iterator pos = s1.find(30);
// if (pos != s1.end())
// {
// //*pos = 30;
// //s1.erase(pos);
// }
// //s1.erase(50);
//
// // [3, 6]
// SetIter first, last;
// first = s1.lower_bound(3);
// last = s1.upper_bound(6);
//
// s1.erase(first, last);
//
// it1 = s1.begin();
// while (it1 != s1.end())
// {
// cout<<*it1<<" ";
// ++it1;
// }
// cout<<endl;
//
// if (s1.count(3))
// {
// cout<<"在"<<endl;
// }
// else
// {
// cout<<"不在"<<endl;
// }
//}
#include<map>
//template<class k, class v>
//struct pair
//{
// k first;
// v second;
//};
void test_map()
{
map<string, string> dict;
dict.insert(pair<string, string>("left", "左边"));
dict.insert(pair<string, string>("right", "右边"));
dict.insert(pair<string, string>("string", "字符串"));
map<string, string>::iterator dIt = dict.begin();
while (dIt != dict.end())
{
cout<<(*dIt).first<<":"<<(*dIt).second<<endl;
cout<<dIt->first<<":"<<dIt->second<<endl;
++dIt;
}
//
map<string, int> countMap;
string strs[] = {"sort", "left", "sort", "right"};
for (size_t i = 0; i < sizeof(strs)/sizeof(strs[0]); ++i)
{
//map<string, int>::iterator ret = countMap.find(strs[i]);
//if (ret != countMap.end())
//{
// ret->second++;
//}
//else
//{
// //countMap.insert(pair<string, int>(strs[i], 1));
// countMap.insert(make_pair(strs[i], 1));
//}
// 研究
countMap[strs[i]]++;
}
}
//#include <set>
//
//void test_set()
//{
// typedef set<int>::iterator SetIter;
// set<int> s1;
// s1.insert(1);
// //s1.insert(3);
// s1.insert(1);
// s1.insert(5);
// s1.insert(7);
// s1.insert(2);
// s1.insert(4);
//
// set<int>::iterator it1 = s1.begin();
// while (it1 != s1.end())
// {
// cout<<*it1<<" ";
// ++it1;
// }
// cout<<endl;
//
// set<int>::iterator pos = s1.find(30);
// if (pos != s1.end())
// {
// //*pos = 30;
// //s1.erase(pos);
// }
// //s1.erase(50);
//
// // [3, 6]
// SetIter first, last;
// first = s1.lower_bound(3);
// last = s1.upper_bound(6);
//
// s1.erase(first, last);
//
// it1 = s1.begin();
// while (it1 != s1.end())
// {
// cout<<*it1<<" ";
// ++it1;
// }
// cout<<endl;
//
// if (s1.count(3))
// {
// cout<<"在"<<endl;
// }
// else
// {
// cout<<"不在"<<endl;
// }
//}
#include<map>
//template<class k, class v>
//struct pair
//{
// k first;
// v second;
//};
void test_map()
{
map<string, string> dict;
dict.insert(pair<string, string>("left", "左边"));
dict.insert(pair<string, string>("right", "右边"));
dict.insert(pair<string, string>("string", "字符串"));
map<string, string>::iterator dIt = dict.begin();
while (dIt != dict.end())
{
cout<<(*dIt).first<<":"<<(*dIt).second<<endl;
cout<<dIt->first<<":"<<dIt->second<<endl;
++dIt;
}
//
map<string, int> countMap;
string strs[] = {"sort", "left", "sort", "right"};
for (size_t i = 0; i < sizeof(strs)/sizeof(strs[0]); ++i)
{
//map<string, int>::iterator ret = countMap.find(strs[i]);
//if (ret != countMap.end())
//{
// ret->second++;
//}
//else
//{
// //countMap.insert(pair<string, int>(strs[i], 1));
// countMap.insert(make_pair(strs[i], 1));
//}
// 研究
countMap[strs[i]]++;
}
}
阅读全文
0 0
- map_set
- map_set
- 【第10章 关联容器】多关键字Map_Set实例
- 界面设计必备,常用字体规范
- ADB命令汇总,比如adb devices之类的
- Oracle知识原理详解
- [知了堂学习笔记]_JavaScript之typeof运算符
- DBUtils
- map_set
- Spring与Redis的整合
- Android实现异步的几种方法
- 3-6 静态数据成员与静态成员函数
- VS2010出现重复的代码项原因及解决方式
- 便利宝商家APP官方版V2.3.0下载 | 银盒子便利宝商家版下载
- Logrotate日志切割报错 文件不再同一个用户组下
- [知了堂学习笔记] javascript 内置对象
- Kubernetes学习之 Hadoop cluster in Kubernetes