zoukankan      html  css  js  c++  java
  • c++ 容器类

    #include <iostream>
    #include <vector>
    #include <list>
    #include <map>
    using namespace std;
    
    void test_map();
    
    struct Person{
        string name;
        int age;
    };
    
    int main()
    {
        vector<Person> vs;
        //list<Person> vs;
    
        Person a, b;
        a.name = "xiaoa";
        a.age = 7;
    
        b.name = "xiaob";
        b.age = 9;
    
        vs.push_back(a);
        vs.push_back(b);
    
        vector<Person>::iterator it;
        for(it=vs.begin(); it!=vs.end(); it++)
        {
            cout << (*it).name << "	" << (*it).age << endl;
            cout << it->name << "	" << it->age <<endl;
        }
        cout << "#########################" << endl;
        typedef vector<Person>::iterator PI;
        for(PI i=vs.begin(); i!=vs.end(); i++)
        {
            cout << (*i).name << "	" << (*i).age << endl;
            cout << i->name << "	" << i->age <<endl;
        }
        cout << "#########################" << endl;
        test_map();
        return 0;
    }
    
    
    void test_map()
    {
    
        map<string, Person> records;
    
        Person a, b;
        a.name = "xiaoa";
        a.age = 7;
    
        b.name = "xiaob";
        b.age = 9;
    
        records.insert(pair<string, Person>(a.name, a));
        records.insert(pair<string, Person>(b.name, a));
    
        cout << "#########################" << endl;
    
        map<string, Person>::iterator rec_iter;
        for(rec_iter=records.begin(); rec_iter!=records.end(); rec_iter++)
        {
            cout << rec_iter->first << "[" << rec_iter->second.name << rec_iter->second.age << "]" << endl;
        }
    }
  • 相关阅读:
    PHP文件系统处理
    JavaScript数据类型
    JavaScript操作符
    JavaScript语法
    在 HTML 中使用JavaScript
    JavaScript概述
    PHP数组
    PHP基本语法
    Eclipse署动态web项目方法
    xml约束技术之dtd
  • 原文地址:https://www.cnblogs.com/i80386/p/4363029.html
Copyright © 2011-2022 走看看