c++输出vector的个数到变量ss中ss为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/gCua 著作权归作者所有。请勿转载和采集!