65,210
社区成员
发帖
与我相关
我的任务
分享
array<int, 5> arr = {{1, 2, 3, 4, 5}};
g++编译的话,可能需要打开-std=c++11或者-std=c++0x选项,vs2010及以上默认支持,08没有试过,不敢乱说。如果大括号只使用一层的话,g++ 4.7.2是编译不过的。
因为array模板的实现就是一个struct内面一个定长数组,但因为这个是标准库的,所以便于别人理解代码。加上array提供的STL接口,也是很好用的。
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;
}
}
std::map<int, std::array<int, 5> > arrays;
c++03
std::map<int, boost::array<int, 5> > arrays;