C++11 array数组的测试

测试环境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类内部数组
//
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值