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]]++;
}
}