首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

取出map中的内容,该怎么处理

2012-02-14 
取出map中的内容请问map容器中如 map int,vector unsigned int如何取出其中第二项的内容vector unsig

取出map中的内容
请问map容器中如 map <int,vector <unsigned int>   >   如何取出其中第二项的内容vector <unsigned int>   ?

[解决办法]
#include <map>
#include <vector>
#include <iostream>

using namespace std;

int main() {

typedef map <int,vector <unsigned int> > IntToVec;

IntToVec aIntMap;

vector <unsigned int> a(10);
vector <unsigned int> b(10);

for (int i=0; i <10; ++i) {
a[i]= i;
b[i]= 2*i;
}

aIntMap[-1] = a;
aIntMap[1] = b;

for ( IntToVec::iterator it = aIntMap.begin(); it!=aIntMap.end(); ++it) {
vector <unsigned int> & uv = it-> second;
for (int i=0; i <uv.size(); ++i) cout < <uv[i] < <endl;
}


}

热点排行