std::map

map<int,string> m_mapTest;
m_mapTest.insert(make_pair(1,"kong"));
m_mapTest.insert(make_pair(2,"yang"));
m_mapTest.insert(make_pair(1,"hello1"));
m_mapTest.insert(make_pair(3,"hello3"));
m_mapTest.insert(make_pair(2,"hello2"));

map<int,string>::iterator it = m_mapTest.begin();
for(;it!=m_mapTest.end();it++)
{
string sTem = (*it).second;
::OutputDebugString(sTem.c_str());
::OutputDebugString("\n");
}

输出结果:

kong
yang
hello3

时间: 2024-12-17 12:06:43

std::map的相关文章

std::map使用结构体自定义键值

使用STL中的map时候,有时候需要使用结构题自定义键值,比如想统计点的坐标出现的次数 struct Node{ int x,y; }; ...... map<Node,int>mp; mp[(Node){x,y}]++; 这样子的话,会出现一堆报错 c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_function.h||In instantiation of 'bool std::less<_Tp>::operator()(

c++ how to make your own class a valid key type for std::map?

In Java, if you want your own class to be a valid key type of the container, you just need to make it implement the interface "Comparable", and then it'll work properly. How about in C++? I was wondering whether C++ has offered some kind of mech

std::map常用方法

map<string, int> Employees; Employees["Mike C."] = 12306; Employees.insert(make_pair("Peter Q.", 5328)); std::map常用方法,布布扣,bubuko.com

STL之std::set、std::map的lower_bound和upper_bound函数使用说明

由于在使用std::map时感觉lower_bound和upper_bound函数了解不多,这里整理并记录下相关用法及功能. STL的map.multimap.set.multiset都有三个比较特殊的函数,lower_bound.upper_bound.equal_range. 原型如下: iterator lower_bound (const value_type& val) const; iterator upper_bound (const value_type& val) con

stl std::map容器排序及使用注意事项 .

01.#include "stdafx.h" 02.#include <map> 03.#include <iostream> 04. 05.int _tmain(int argc, _TCHAR* argv[]) 06.{ 07. /** 08. * map中的每个元素都是一个pair类型 09. * 对于插入其中的元素都会默认按键值升序排列好 10. */ 11. 12. std::map<int, int> m; 13. m.insert(st

RAD C++Builder xe7 std::map xtree BUG

c++Builder 6 下的std::map还能用,有代码提示. 换到xe7,代码提示出来就一个tt.operator [](),代码没法往下写了. 最后把Target Platforms切换到64 bit windows 竟然可以了!!!

std::map Intro

#include <queue>#include <map>#include <iostream>#include <string.h> class TestU {public: TestU(char *); ~TestU(); char *getData();private: char *data;}; TestU::TestU(char *d){ if(d) { int len = strlen(d); data = new char[len + 1];

C++ std::map::erase用法及其陷阱

1.引入: STL的map中有一个erase方法用来从一个map中删除制定的节点 eg: map<string,string> mapTest; typedef map<string,string>::iterator ITER; ITER iter=mapTest.find(key); mapTest.erase(iter); 像上面这种删除单个节点,map的行为不会出现问题,但是当在一个循环里用的时候,往往会被误用. 2.陷阱 eg: for(ITER iter=mapTest

std::map插入已存在的key时,key对应的内容不会被更新

std::map插入已存在的key时,key对应的内容不会被更新,如果不知道这一点,可能会造成运行结果与预期的不一致 “Because element keys in a map are unique, the insertion operation checks whether each inserted element has a key equivalent to the one of an element already in the container, and if so, the

boost::unordered_map 和 std::map 的效率 与 内存比较

例子链接:http://blog.csdn.net/gamecreating/article/details/7698719 结论: unordered_map 查找效率快五倍,插入更快,节省一定内存.如果没有必要排序的话,尽量使用 hash_map(unordered_map 就是 boost 里面的 hash_map 实现). boost::unordered_map 和 std::map 的效率 与 内存比较