1. 程式人生 > >C++中二維vector賦值

C++中二維vector賦值

vector<vector<int> > nums(8,vector<int>(13)); //二維陣列的行數為8,列數為13。<int>後一定要加一個空格,否則會被判別為操作符>>出錯
int b[8][13] = {{0,0,1,0,0,0,0,1,0,0,0,0,0},
                {0,0,0,0,0,0,0,1,1,1,0,0,0},
                {0,1,1,0,1,0,0,0,0,0,0,0,0},
                {0,1,0,0,1,1,0,0,1,0,1,0,0},
                {0,1,0,0,1,1,0,0,1,1,1,0,0},
                {0,0,0,0,0,0,0,0,0,0,1,0,0},
                {0,0,0,0,0,0,0,1,1,1,0,0,0},
                {0,0,0,0,0,0,0,1,1,0,0,0,0}};
for(int i = 0; i < 8; i++){
    for(int j = 0; j < 13; j++){
        nums[i][j] = b[i][j];
    }
}