map中可以存放一个数组么???
有一个数组:int array[5] = {0,1,2,3,4};
如何把这个数组放到一个map中
伪代码即:map<int, 数组> mapArray;
然后再把array这个数组放到mapArray中,key为0
最后遍历出array里面的值
[解决办法]
除了vector和8楼说的自己定制
你也可以选用std::array
c++11
std::map<int, std::array<int, 5> > arrays;
std::map<int, boost::array<int, 5> > arrays;
array<int, 5> arr = {{1, 2, 3, 4, 5}};
array<int, 5> a = {{1, 2, 3, 4, 5}};
typedef map<int, array<int, 5> > map_type;
map_type m;
m.insert(map_type::value_type(10, a));
map_type::const_iterator it = m.find(10);
if (it != m.end())
{
const array<int, 5>& ref = it->second;
typedef array<int, 5>::const_iterator iterator;
for (iterator it2 = ref.begin(); it2 != ref.end(); ++it2)
{
std::cout << *it2 << std::endl;
}
}