STL——array
来源:互联网 发布:手机淘宝删差评怎么删 编辑:程序博客网 时间:2024/06/06 15:01
参考CPP标准文档
Arrays are fixed-size sequence containers.
c++11 中的array是固定大小的的线性序列容器
特点:
1. 他是严格的序列化排序的线性容器。
2. 连续存储的。
3. 大小固定,不能动态拓展。
array 使用构造函数和析构函数管理空间, 容器大小是编译时常量。没有空间和时间开销。。所以没有。push_back, pop_back等成员函数。
初始化方法
array<int, 5> myArray;myArray.fill(0);array<int, 5> myArray2 = {1,2,3,4,5};array<int, 5> myArray3;for (int i = 0; i < 5; i++){myArray3[i] = i;}
std::array::swap
交换两个array条件是必须有相同的类型和容器大小
array的关系运算符操作
#include <iostream>#include <array>int main (){ std::array<int,5> a = {10, 20, 30, 40, 50}; std::array<int,5> b = {10, 20, 30, 40, 50}; std::array<int,5> c = {50, 40, 30, 20, 10}; if (a==b) std::cout << "a and b are equal\n"; if (b!=c) std::cout << "b and c are not equal\n"; if (b<c) std::cout << "b is less than c\n"; if (c>b) std::cout << "c is greater than b\n"; if (a<=b) std::cout << "a is less than or equal to b\n"; if (a>=b) std::cout << "a is greater than or equal to b\n"; return 0;}Output:
a and b are equalb and c are not equalb is less than cc is greater than ba is less than or equal to ba is greater than or equal to b
0 0
- STL——array
- STL学习笔记— —容器array
- STL学习笔记2— —容器array
- stl : array
- Codeforces Round #258 (Div. 2)——B. Sort the Array(STL-reverse)
- C++ STL之array
- <STL系列>array
- C++ stl array数组
- STL源码解析Array
- STL容器array
- STL::array之数组容器
- STL array的介绍(1)
- STL array的cbegin(5)
- c++的STL的array
- Javascript—Array
- LeetCode189—Rotate Array
- C-pointer—array
- STL —— STL六大组件
- mac系统下vi编辑器中的关键字高亮设置
- 淘宝开放平台API交流
- 视音频编解码技术零基础学习方法
- 理解HTTP幂等性
- linux快速修改用户密码
- STL——array
- apache shiro集群实现(一) session共享
- oralce删除某字段值相同的记录
- miniupnp映射本地端口到外网
- JMeter—丰富报表功能PerfMon插件
- 油丹
- 链表操作
- iOS程序发布测试3-生成ad hoc证书
- cocos2dx setDisplayStats