美文网首页
【vector>】初始化一维&二维数组

【vector>】初始化一维&二维数组

作者: 唯师默蓝 | 来源:发表于2020-08-31 17:20 被阅读0次
#include <string>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int x = 5, y = 5;
    vector<vector<int>> A(x, vector<int>(y, 0));
    A = {{1,4,7,11,15},{2,5,  8, 12, 19},{3,  6,  9, 16, 22},{10, 13, 14, 17, 24},{18, 21, 23, 26, 30} };
    cout << "Size:" << A.size() << endl;
    for (int i = 0; i <5; i++) {
        for (int j = 0; j <5; j++) {
            cout << A[i][j] << " ";
        }
        cout << endl;
    }
    system("pause");
    return 0;
}
image.png
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    vector<int> x;
    x = { 2, 3, 1, 0, 2, 5, 3 };
    for (int i = 0; i < x.size(); i++) {
        cout << x[i] << ' ';
    }
    cout << endl;
    system("pause");
    return 0;
}
image.png

相关文章

网友评论

      本文标题:【vector>】初始化一维&二维数组

      本文链接:https://www.haomeiwen.com/subject/aqcpsktx.html