An array container, which is a container for storing arrays, is an extension of the Type C array, and can be manipulated using iterators;
For example, "Std::array<int, 5>", it should be noted that if directly assigned, "Std::array<int, 5> ia = {1, 2, 3, 4, 5};"
There will be a warning under gcc: "Missing braces around initializer for ' std::array<int, 5u>::value_type [5] {aka int [5]} ' [-wmissing-bra CES] "
The reason is not in the way of initializing the array, add a group of "{}", such as: "Std::array<int, 5> ia ={{1, 2, 3, 4, 5}};", so that the parameter satisfies the int[5], and then assigns the value;
Arrays are usually assigned in the initialization process, if you want to replace the existing values, one method is to traverse all the values, more complex;
Another method is to reproduce the value by copying to achieve a fast assignment;
Code:
* * * test.cpp * * Created on:2013.11.12 * author:caroline
//*eclipse CDT; 4.7.1*/
#include <iostream>
#include <array>
int main (void) {
std::array<int, 5 > ia = {1, 2, 3, 4, 5}};
for (const auto I:ia)
std::cout << i << "";
Std::cout << Std::endl;
Std::array<int, 5> ia2; Empty array
//ia2 = {1, 2, 3, 4, 5};//error
IA2 = ia;
for (const auto I:IA2)
std::cout << i << "";
Std::cout << Std::endl;
return 0;
}
Author: csdn Blog spike_king
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/