zoukankan      html  css  js  c++  java
  • array详解

    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

  • 相关阅读:
    ES6(二)
    ES6
    bootstrap
    数组对象
    bootstrap
    html5(二)
    css3转换、动画、布局
    整理的一些兼容写法
    css渐变、背景、过渡、分页
    css3(一)
  • 原文地址:https://www.cnblogs.com/boost/p/10397111.html
Copyright © 2011-2022 走看看