数组容器, 是存储数组的容器, 是C类型数组的扩充, 可以使用迭代器进行操作;
例如"std::array", 需要注意的是, 如果直接进行赋值, "std::array ia = {1, 2, 3, 4, 5}; "
在GCC下会有警告: "missing braces around initializer for 'std::array::value_type [5] {aka int [5]}' [-Wmissing-braces]"
原因是与初始化数组的方式不符, 再加一组"{}"即可, 如: "std::array ia ={{1, 2, 3, 4, 5}};", 使参数满足int[5], 再进行赋值;
数组一般在初始化过程中赋值, 如果想替换已有的值, 一种方法是遍历所有的值, 较复杂;
另一种方法是通过复制去重新赋值, 实现快速赋值;
代码:
/* * test.cpp * * Created on: 2013.11.12 * Author: Caroline */ /*eclipse cdt; gcc 4.7.1*/ #include#include int main (void) { std::array ia = {{1, 2, 3, 4, 5}}; for(const auto i : ia) std::cout << i << " "; std::cout << std::endl; std::array ia2; // 空数组 //ia2 = {1, 2, 3, 4, 5}; //错误 ia2 = ia; for(const auto i : ia2) std::cout << i << " "; std::cout << std::endl; return 0; }