C++ 获取vector大小并赋值给int变量
C++ 获取vector大小并赋值给int变量
可以使用vector的size()函数来获取其元素个数,然后将其赋值给变量ss,如下所示:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vec = {1, 2, 3, 4, 5};
int ss = vec.size();
cout << "The size of the vector is: " << ss << endl;
return 0;
}
输出结果为:
The size of the vector is: 5
原文地址: https://www.cveoy.top/t/topic/owJ9 著作权归作者所有。请勿转载和采集!