用map嵌套vector实现multimap功能

最近迷上了泛型编程,在一个项目中需要用到一个变长映射,于是用map+vector+结构体实现了multimap的基本功能。

特改个demo存档。

//---------------------------------------------------------------------------
#include 
#include
#include 
#include 
using namespace std;
//---------------------------------------------------------------------------
typedef struct test
{
    char nn[8];
    int xx;
    int yy;
}  Mystruct;

typedef vector< Mystruct>  Myvctor;
typedef map  Mymap;

int main(int argc, char *argv[])
{
    Mystruct st1[2]= {{"aa",12,34},{"bb",21,43}};
    Mystruct st2[3]= {{"AA",11,22},{"BB",33,44},{"CC",55,66}};
    Myvctor myvctor(st1,st1+2);  //直接把数组初始化进来
    Mymap mymap;
    mymap.insert(pair(1,myvctor));
    myvctor.clear();
    for(int i=0; i(3,myvctor));
    cout<<"*******  遍 历  *******" <second.begin(); it != iter->second.end(); it++)
        {
            cout<first <<" : "<< (*it).nn<<", "<<(*it).xx<<", "<<(*it).yy<<", "<second.begin(); it != iter->second.end(); it++)
        {
            cout<first <<" : "<< (*it).nn<<", "<<(*it).xx<<", "<<(*it).yy<<", "<
用map嵌套vector实现multimap功能_第1张图片

你可能感兴趣的:(bcb,C++,泛型)