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;
        }
    }
  • 相关阅读:
    G
    O
    M
    K-Hero
    J
    G
    F
    Codeforces Round #327 (Div. 2) A Wizards' Duel (水题)
    C++各大有名科学计算库(转)
    矩阵算法 高斯消元 行列式 矩阵的秩
  • 原文地址:https://www.cnblogs.com/i80386/p/4363029.html
Copyright © 2011-2022 走看看