牛骨文教育服务平台(让学习变的简单)
博文笔记

C++中二维vector赋值

创建时间:2018-01-09 投稿人: 浏览次数:348
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];
    }
}

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。