测试环境VS2013,测试了array的所有方法,并给出了说明(提示,在VS里按下Alt键并纵向拖动鼠标可以纵向选择文本)
#include <iostream>
#include <array>
using namespace std;
int main()
{
array<int, 10> arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
//cout<<arr.at(9)<<endl; //arr[9]
//cout<<arr.back()<<endl; //最后一个
//cout << arr.front() << endl; //第一个
//cout<<*arr.begin()<<endl; //第一个的指针
//cout<<*arr.end()<<endl; //最后一个的指针
//cout << *arr.cbegin() << endl; //同begin()
//cout << *arr.cend() << endl; //同end()
/* cbegin()定义
const_iterator cbegin() const _NOEXCEPT
{ // return iterator for beginning of nonmutable sequence
return (((const _Myt *)this)->begin());
}*/
//cout << *arr.crbegin() << endl; //翻转的begin()
//cout<<*arr.rbegin()<<endl; //翻转的begin()
//cout << *arr.crend() << endl; //翻转的end();
//cout << arr.rend() << endl; //翻转的end();
//cout << arr.data() << endl; //数组指针
//cout<<arr.empty()<<endl; //判断数组是空
//arr.assign(4); //全部替换成4
//arr.fill(5); //填充数组,同assign
fill()和assign()的定义//
// void assign(const _Ty& _Value)
// { // assign value to all elements
// _Fill_n(_Elems, _Size, _Value);
// }
//
// void fill(const _Ty& _Value)
// { // assign value to all elements
// _Fill_n(_Elems, _Size, _Value);
// }
//cout << arr.max_size() << endl; //数组长度
//cout << arr.size()<<endl; //数组长度 ,同上,返回值一模一样
array<int, 10> a2 = { 0 };
//arr.swap(a2); //交换数组
//两种遍历数组的方法
for (int i : arr)
cout << i << " ";
cout << endl;
for (int i = 0; i < a2.size(); i++)
{
cout << a2[i]<<" ";
}
int a;
cin >> a;
return 0;
///以下是内部数据///
//arr._Xran(); //记录数组溢出错误的函数
//arr._EEN_SIZE; //记录数组长度的枚举
//arr._Elems; //array类内部数组
//
}