美文网首页
C++ 嵌套 vector 初始化

C++ 嵌套 vector 初始化

作者: 衣介书生 | 来源:发表于2020-04-04 16:14 被阅读0次

    注:C++11 支持,g++ test.cpp -std=c++11

    #include<iostream>
    #include<string>
    #include<vector>
    using namespace std;
    
    
    int main() {
    
        vector<vector<int> > board1 (10, vector<int>(10, 0));
        int m = board1.size();
        int n = board1[0].size();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                cout<< board1[i][j]<<" ";
            }
            cout<<endl;
        }
    
        vector<vector<char> > board2 = {{'X','.','.','X'}, {'.','.','X','X'}, {'X','X','.','.'}};
        m = board2.size();
        n = board2[0].size();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                cout<< board2[i][j]<<" ";
            }
            cout<<endl;
        }
    }
    
    
    
    

    相关文章

      网友评论

          本文标题:C++ 嵌套 vector 初始化

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