zoukankan      html  css  js  c++  java
  • STL容器嵌套

    vector  STL 中的标准容器之一 :动态数组

    #define _CRT_SECURE_NO_WARNINGS
    #include <iostream>
    using namespace std;
    #include <vector>
    #include <algorithm>
    
    
    void myPrint(int v)
    {
        cout << v << " ";
    }
    void test01()
    {
        //定义一个大容器 里面放着储存int类型的小容器类型
        vector<vector<int>> v;
        vector<int> v1;
        vector<int> v2;
        vector<int> v3;
    
        for (int i = 0; i < 5; i++)
        {
            v1.push_back(i);
            v2.push_back(i + 10);
            v3.push_back(i + 100);
        }
        v.push_back(v1);
        v.push_back(v2);
        v.push_back(v3);
    
        //遍历数据
        for (vector<vector<int>>::iterator it = v.begin(); it != v.end(); it++)
        {
            for_each((*it).begin(), (*it).end(), myPrint);
            cout << endl;
        }
    }
    int main()
    {
        test01();
        system("Pause");
        return 0;
    }

    结果:

  • 相关阅读:
    hdu 4508
    hdu 4506
    hdu 4505
    hdu 1525
    hdu 2212
    (贪心)删数问题
    (最短路 Dijkstra) hdu 1544
    (次小生成树) poj 1679
    (prim)hdu 1102
    (kruskal)hdu 1863
  • 原文地址:https://www.cnblogs.com/yifengs/p/15188276.html
Copyright © 2011-2022 走看看