从两个向量创建映射 [英] creating a map from two vectors
本文介绍了从两个向量创建映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有两个stl向量vect1,vect2和我想从他们产生一个地图,所以vect1的第一个元素将对应于vect2的第一个元素,依此类推。
我如何以最简单的方式做呢?
If I have two stl vectors vect1, vect2 and I want to produce from them a map, so first element from vect1 will correspond to first element in vect2 and so on. How can I do that in the most simple way?
推荐答案
std::vector<int> a, b;
// fill vectors here...
std::map<int, int> m;
assert(a.size() == b.size());
for (size_t i = 0; i < a.size(); ++i)
m[a[i]] = b[i];
这篇关于从两个向量创建映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文