C++ array 数组函数

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;
}

结果为:

 (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

无聊就学习 反正没事干
原文地址:https://www.cnblogs.com/miao-xixixi/p/12678053.html