开发者社区 问答 正文

关于 二维的vector push_back怎么用?

关于 二维的vector push_back怎么用?

展开
收起
a123456678 2016-03-09 13:41:09 3014 分享 版权
1 条回答
写回答
取消 提交回答
  •  #include<iostream>
    #include<vector>
    using namespace std;
    
    typedef struct point
    {
        int x;
        int y;
    }POINT;
    
    int main()
    {
        vector<vector<POINT>> a;
        for(int i = 0; i < 5; i++)
        {
            vector<POINT> b;
            a.push_back(b);
            for(int j = 0; j < 4; j++)
            {
                POINT c = {i, j};
                a[i].push_back(c);
            }
        }
    
      //用迭代器遍历打印
        vector<vector<POINT>>::iterator vec_it;
        for(vec_it = a.begin(); vec_it != a.end(); vec_it++)
        {
            vector<POINT>::iterator it;
            for(it = (*vec_it).begin(); it != (*vec_it).end(); it++)
            {
                cout << " [" <<it->x << "," << it->y << "] ";
            }
            cout << endl;
        }
        system("pause");
    }
    2019-07-17 18:55:57
    赞同 展开评论
问答地址: