Array — статический последовательный линейный контейнер
#include "stdafx.h" #include <iostream> #include <array> #include <cstring> //using namespace std; int main() { std::array<int, 0> myarray_empty; std::array<int, 10> myarray = {13,45,77,9,4,88,9,53,2,18}; myarray.front() = 101; for (auto it = myarray.begin(); it != myarray.end(); it++) { std::cout << " "<< *it; } std::cout <<"\n"; for (auto it = myarray.rbegin(); it != myarray.rend(); it++) { std::cout << " " << *it; } std::cout << "\n" << myarray.front(); std::cout << "\n" << myarray.back(); std::cout << "\n" << myarray.size(); std::cout << "\n" << myarray.max_size(); std::cout << "\n" << myarray.empty(); std::cout << "\n" << myarray_empty.empty(); std::cout << "\n"; std::array<int, 10> myarray_i; unsigned int i = 0; for (i=0; i<10; i++) { myarray_i[i] = i; } for (i = 0; i < 10; i++) { std::cout << " " << myarray_i[i]; } std::cout << "\n"; std::array<int, 10> myarray_at; for (i = 0; i < 10; i++) { myarray_i.at(i) = i; } for (i = 0; i < 10; i++) { std::cout << " " << myarray_i.at(i); } const char* str = "Go..."; std::array<char, 12> array_ch; std::memcpy(array_ch.data(), str, 12); std::cout << "\n" << array_ch.data(); std::cout << "\n"; myarray_at.fill(3); for (int& x : myarray_at) { std::cout << " " << x; } std::cout << "\n"; std::array<int, 5> myarray_first = {1,2,3,4,5}; std::array<int, 5> myarray_second = {3,7,11,14,18}; myarray_second.swap(myarray_first); for (int& x : myarray_second) { std::cout << " " << x; } std::cout << "\n"; if (myarray_first != myarray_second) { std::cout << "not equal"; } system("pause"); return 0; }