zoukankan      html  css  js  c++  java
  • STL array

     先声明,这个STL 容器很少有人使用,因为必须要指定大小,一般都用vector或list 了。

    template < class T, size_t N > class array;

    Container properties

    Sequence
    Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by their position in this sequence.
    Contiguous storage(连续的)
    The elements are stored in contiguous memory locations, allowing constant time random access to elements. Pointers to an element can be offset to access other elements.
    Fixed-size aggregate(集合,聚集)
    The container uses implicit constructors and destructors to allocate the required space statically. Its size is compile-time constant. No memory or time overhead.
    用法和vector差不多:
    // array::begin example
    #include <iostream>
    #include <array>
    
    int main ()
    {
      std::array<int,5> myarray = { 2, 16, 77, 34, 50 };
    
      std::cout << "myarray contains:";
      for ( auto it = myarray.begin(); it != myarray.end(); ++it )
        std::cout << " " << *it;
    
      std::cout << std::endl;
    
      return 0;
    }
  • 相关阅读:
    selenium 难定位元素、时间插件
    列表生成式
    三元表达式
    监控日志
    非空即真
    深拷贝浅拷贝
    元组
    list字典嵌套
    2021
    布尔类型
  • 原文地址:https://www.cnblogs.com/youxin/p/2592318.html
Copyright © 2011-2022 走看看