首页 > 其他 > 详细

array详解

时间:2019-02-18 20:04:59      阅读:246      评论:0      收藏:0      [点我收藏+]

array和vector大致是相同的,区别在于array的大小是固定的。不能增加和缩小。另外array的swap()函数和vector的swap()函数在算法复杂度上是有区别的,array.swap()函数是线性时间复杂度,vector,swap()是常量时间复杂度。在定义array的时候需要两个参数。

#include <iostream>
#include <array>
int main()
{
    std::array<int,3> arrayInt= {1,2,3};
    std::cout << "size : " << arrayInt.size() << std::endl;
    for(auto i : arrayInt)
    {
        std::cout << i << " ";
    }
    std::cout << std::endl;

    arrayInt.fill(3);
    std::cout << "fill(3) :  "  << std::endl;
    for(auto i : arrayInt)
    {
        std::cout << i << " ";
    }


    return 0;
}

结果是:

size : 3
1 2 3
fill(3) :
3 3 3

array详解

原文:https://www.cnblogs.com/boost/p/10397111.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!