C++之判断数组元素个数

1.sizeof用于判断数据占据的内存字节数。

如:sizeof(int)的为4。

因此,判断数组的元素个数写法如下:

num=sizeof(array)/size(a[0]);

 

2.判断string类型元素个数

string是字符串,判断字符串中的字符个数

num=string.size();

 

3.判断vector数组的元素个数

vector创建动态数组

num=vector.size();

posted @ 2018-10-24 22:42  程嘿嘿  阅读(17630)  评论(0编辑  收藏  举报