1.头文件:#include<array>

2.和数组有什么区别?

更安全,建议用其代替数组!

3.用法:

array<int ,19>s  代表着 s[19] 并且里面的元素是int型 

值得注意的是 array此时的数组并没有初始化

array 初始化的方法:

(1) 

#include<iostream>
#include<algorithm>
#include<array>
using namespace std;
main(){
    array<int,3>m{0};
    for(auto i:m)
    cout<<m[i]<<" ";
    return 0;
}

结果为:

C++ array 数组函数

 

 (2)

代码为:

#include<iostream>
#include<algorithm>
#include<array>
using namespace std;
main(){
    array<int,3>m{};
    for(auto i:m)
    cout<<m[i]<<" ";
    return 0;
}

 

参考链接:

https://blog.csdn.net/zhengqijun_/article/details/81566109

相关文章:

  • 2022-12-23
  • 2021-09-16
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
猜你喜欢
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-08-17
相关资源
相似解决方案