stl标准模板库

"array" is a container in C++ STL, which has fixed size, which is defined in "array" header.

“ array”是C ++ STL中的一个容器,具有固定大小,在“ array”标头中定义。

Declaration:

宣言:

    array <data_type, size> array_name = {initializer_list};
Example:
array<int,5> values {10, 20, 30, 40, 50};

Array class's common functions:

数组类的常用功能:

  1. array::operator[] - Gets and sets a reference to an element based on given index.

    array :: operator [] -根据给定的索引获取并设置对元素的引用。

  2. array.empty() - Returns true if array is empty

    array.empty() -如果数组为空,则返回true

  3. array.size() - Returns the total number of elements in the array

    array.size() -返回数组中元素的总数

  4. array.front() - Return the first element

    array.front() -返回第一个元素

  5. array.back() - Returns the last element

    array.back() -返回最后一个元素

  6. array.at(index) - Returns the element from given index

    array.at(index) -返回给定索引中的元素

  7. array.begin() - Returns the reference pointing to the first element

    array.begin() -返回指向第一个元素的引用

  8. array.end() - Returns the reference punting to the last element

    array.end() -返回指向最后一个元素的引用

Example:

例:

#include <iostream>
#include <array>
using namespace std;
int main()
{//array declaring and initialization
array<int, 5> arr = {10, 20, 30, 40, 50};
//checking array is empty or not by using empty()
if(arr.empty())
cout<<"Array is empty!!!"<<endl;
else
cout<<"Array is not empty!!!"<<endl;
//Array functions
cout<<"size: "  << arr.size() <<endl;
cout<<"first element: " << arr.front()    <<endl;
cout<<"last  element: " << arr.back() <<endl;
cout<<"0th element: " << arr.at(0)    <<endl;
cout<<"3rd element: " << arr.at(3)    <<endl;
//printing all array elements are: ";
for(auto i = arr.begin () ; i != arr.end(); i++)
cout<<*i<<" ";
cout<<endl;
return 0;
}

Output

输出量

    Array is not empty!!!size: 5first element: 10last  element: 500th element: 103rd element: 4010 20 30 40 50

Reference: C++ std::array

参考: C ++ std :: array

翻译自: https://www.includehelp.com/stl/array-in-cpp-standard-template-library-with-its-common-functions.aspx

stl标准模板库

stl标准模板库_C ++标准模板库(STL)中的数组及其常用功能相关推荐

  1. stl标准模板库_C ++标准模板库(STL)中的array :: fill()

    stl标准模板库 fill() is a member function of "array container", which sets a given value to all ...

  2. 常用标准库_C语言标准IO库常用函数

    1.标准IO文件操作 1.1 标准IO--->C语言提供的标准IO库<stdio.h> 1.1.1 printf 函数原型:int printf(constchar *format, ...

  3. stl clocklist 查找元素_C++|通俗理解STL

    "存储程序"是电子计算机技术一个很重要的概念.程序能在计算机上运行,必须先让程序代码从其他的一些存储介质(如光盘或硬盘)读入到内存,然后才能由控制器从内存读取.解释并产生控制信号, ...

  4. c++ 的 stl模板库_C ++中的标准模板库(STL)

    c++ 的 stl模板库 Standard Template Library (STL) is a collection of standard C++ template classes. It co ...

  5. C++标准库和标准模板库(转)

    转自原文http://blog.csdn.net/sxhelijian/article/details/7552499 C++强大的功能来源于其丰富的类库及库函数资源.C++标准库的内容总共在50个标 ...

  6. C++标准库和标准模板库

    C++强大的功能来源于其丰富的类库及库函数资源.C++标准库的内容总共在50个标准头文件中定义. 在C++开发中,要尽可能地利用标准库完成.这样做的直接好处包括: (1)成本:已经作为标准提供,何苦再 ...

  7. C++17标准STL库并行策略在GCC编译器中的替代实现方法

    C++17标准STL库并行策略在GCC编译器中的替代实现方法 严正声明:本文系作者davidhopper原创,未经许可,不得转载.  2019年8月5日更新: GCC 9.1.0可支持C++ 17标 ...

  8. C++库介绍-标准库、类库

    目录: 1.标准库 2.GUI库 3.网络通信 4.XML 5.科学计算 6.游戏开发 7.线程 8.序列化 9.字符串 10.综合 11.其他 12.C++重要人物网站 C++类库介绍 再次体现了C ...

  9. STM32 HAL库、标准外设库、LL库(STM32 Embedded Software)

    STM32 Embedded Software 工作以来一直使用ST的STM32系列芯片,ST为开发者提供了非常方便的开发库.到目前为止,有标准外设库(STD库).HAL库.LL库 三种.前两者都是常 ...

最新文章

  1. php 使用netstat -an,netstat -an 查看端口
  2. EDM营销之如何使邮件列表更加有效
  3. 【Java】猜数字小游戏
  4. (33)SystemVerilog语言编写二分频
  5. java操作Linux 调用shell命令,shell脚本
  6. 小米MIX4曝光,颜值真不错
  7. c++ primer第5版中文版.pdf_伍德里奇计量经济学导论现代观点第5版 pdf
  8. Vue图片、视频预览组件(vue-gallery)
  9. linux mmap 作用,LINUX 中的mmap浅析
  10. 选好电线 “家”倍安全
  11. echarts 饼图文字图例多种颜色
  12. 如何添加二级域名(图文超级详细)
  13. JavaScript基础系列之一 快速入门
  14. VIJOS P1540 月亮之眼
  15. Github之First day on Github,带你学习并完成任务点,纯手敲超详细教程!(下)
  16. 这10个超厉害的工具堪称神器,却很少人知道!
  17. matplotlib:使用emoji字体实现简易象形图
  18. python的界面文字翻译_教你用Python实现微信翻译机器人
  19. 自动控制系统的时域分析法——一阶系统的时域分析
  20. 供应链产品经理需要具备的基本能力有哪些?

热门文章

  1. c语言fork()创建线程,操作系统的创建原语是fork()还是creat()?
  2. win2008 mysql端口_使用自定义端口连接SQL Server 2008的方法
  3. 日常问题——VMware下的CentOS7 Ping不通百度
  4. X86和X86_64和AMD64的由来
  5. python文件编码及执行
  6. Android Framework中的Application Framework层介绍
  7. V 8 nfs+drbd+heartbeat
  8. [转]C++中sizeof(struct)怎么计算?
  9. python3绘图_python3绘图示例2(基于matplotlib:柱状图、分布图、三角图等)
  10. vs设计窗口不见了_碳纤维的巅峰:VS沛纳海616V3