c++输出vector的个数
要输出vector的个数,可以使用vector的size()函数,该函数返回vector中元素的数量,具体实现如下:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vec = {1, 2, 3, 4, 5};
cout << "vector size: " << vec.size() << endl;
return 0;
}
输出结果:
vector size: 5
原文地址: https://www.cveoy.top/t/topic/gCtI 著作权归作者所有。请勿转载和采集!