STL的map类型
2015-05-30 09:48
183 查看
关于map的数据类型,可以与set进行比较,我们说set,map都是关联性容器,也即set,map都是根据关键字进行数据存储、读取的,我们说set是关键字和数据相同的关联性容器,而map则是不同的,也即利用数学上的映射关系建立的键值对进行存储和读取。
#include<map> #include<iostream> using namespace std; struct myComp { int a, b, c; myComp() :a(0), b(0), c(0){}; myComp(int aa, int bb, int cc) :a(aa), b(bb), c(cc){}; friend bool operator< (const myComp &la, const myComp &lb); }; inline bool operator< (const myComp &la, const myComp &lb) { if (la.a != lb.a) return la.a < lb.a; if (la.b != lb.b) return la.b < lb.b; if (la.c != lb.c) return la.c < lb.c; return false; } int _tmain(int argc, _TCHAR* argv[]) { map<myComp, char> imap; imap[myComp(4, 5, 0)] = 'q'; imap[myComp(2, 8, 9)] = 'o'; imap[myComp(3, 9, 1)] = 'u'; imap[myComp(3, 10, 1)] = '9'; imap[myComp(3, 9, 0)] = '0'; imap[myComp(11, 11, 11)] = 'g'; map<myComp, char>::iterator iter = imap.begin(); for (; iter != imap.end(); ++iter) { char temp[16] = { 0 }; cout << (iter->first).a << " " << (iter->first).b << " " << (iter->first).c << " " << iter->second << endl; } return 0; }同样的改map的插入操作也是insert_unique操作不允许插入与之前相同的值。
相关文章推荐
- history命令小技巧
- 我的博客
- Hibernate学习总结
- 在webform中调用JS的技巧
- C++ 构造函数 析构函数 拷贝构造函数 运算符重载解析。
- http://guoyifan163.blog.163.com/
- 100w条数据如何插入
- Host is not allowed to connect to this MySQL server 错误的处理方法
- 2.UITabBar Navigation
- 有点迷糊
- sparse Autoencoder(3)---自编码算法与稀疏性
- Javascript实现div层渐隐效果的方法
- Eclipse Java注释模板设置详解
- Qt小软件:TsTranslationTool(ts字符串文件翻译器)
- Java Convert ArrayList<String> to String []
- Android常用控件总结
- 外媒评论:原生安卓已死!
- N的阶乘(N!)中的末尾有多少个0
- 修改iOS应用名称
- Oracle学习(七)之增加日志组