赞
踩
C++获取vector二维数组的行数和列数
代码:
#include <iostream> #include <string> #include <vector> using namespace std; int main(){ //创建4*5二维数组,并将数组元素的值都设为1 vector<vector<int>> dp(4, vector<int>(5, 1)); //打印二维数组 for (int i = 0; i < 4; i++) { for (int j = 0; j < 5; j++) cout << dp[i][j] << " "; cout << endl; } cout << endl; int m = dp.size();//行数 int n = dp[0].size();//列数 cout << "m = " << m << endl; cout << "n = " << n << endl; return 0; }
结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。