STL array的size方法(18)
来源:互联网 发布:mac版qq群文件 编辑:程序博客网 时间:2024/05/01 20:03
std::array::size
constexpr size_type size() noexcept;
返回array里面元素的数目。
The size of an array object is always equal to the second template parameter used to instantiate the array template class (N).
array的size一般都和第二个模版参数一样。
Unlike the language operator sizeof, which returns the size in bytes, this member function returns the size of the array in terms of number of elements.
和sizeof不同,sizeof是返回以bytes单位的大小,该方法是返回元素数目的大小。
例子:
#include <iostream>#include <array>using namespace std;int main(){array<int,5> ai;//{10,20,30,40};auto it=ai.end();cout<<"ai=";for(int i:ai)cout<<i<<" ";cout<<endl;cout<<"size="<<ai.size()<<endl;cout<<"sizeof(ai)="<<sizeof(ai)<<endl;}运行截图:
Parameters
noneReturn Value
The number of elements contained in the array object.
array中元素的数目。
This is a compile-time constant expression (constexpr).这在编译时就是一个常量。
Member type size_type is an alias of the unsigned integral type size_t.Example
123456789101112
// array::size#include <iostream>#include <array>int main (){ std::array<int,5> myints; std::cout << "size of myints: " << myints.size() << std::endl; std::cout << "sizeof(myints): " << sizeof(myints) << std::endl; return 0;}
Possible output:
size of myints: 5sizeof(myints): 20
Complexity
Constant.Iterator validity
No changes.Data races
No contained elements are accessed: concurrently accessing or modifying them is safe.元素不会被访问,同时访问以及修改他们都是安全的。
Exception safety
No-throw guarantee: this member function never throws exceptions.
该方法不会抛出异常。
——————————————————————————————————————————————————————————————————
//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:coderguang@gmail.com
2014-8-30
于GDUT
——————————————————————————————————————————————————————————————————
- STL array的size方法(18)
- STL array的at方法(2)
- STL array的back方法(3)
- STL array的begin方法(4)
- STL array的cend方法(6)
- STL array的crend方法(8)
- STL array的empty方法(10)
- STL array的fill方法(12)
- STL array的front方法(13)
- STL array的operator[]方法(15)
- STL array的rbegin方法(16)
- STL array的rend方法(17)
- STL array的swap方法(19)
- STL array的crbegin方法(7)
- STL array的data方法(9)
- STL array的max_size方法(14)
- STL中的size()方法(13)
- STL array中的end方法(11)
- Android:滑动菜单栏(一)开源项目SlidingMenu的使用
- 阿里8.29,研发笔试题中的两个附加题
- 正则表达式第二篇
- Android.mk中设置PROPERTIES属性
- Android:滑动菜单栏(二)开源项目SlidingMenu的示例
- STL array的size方法(18)
- 链表的冒泡排序
- 二叉树基本操作的程序实现
- 单向链表操作
- C++之练习题41
- mysql日期选择函数
- Android:滑动菜单栏(三)SlidingMenu动画效果的实现
- 点滴的积累---J2SE学习小结
- IntelliJ IDEA设置调试模式的Variables和Watches窗口的变量为Object模式