加文

希望是美好的……
随笔 - 0, 文章 - 209, 评论 - 0, 引用 - 0
数据加载中……

map constructor

#include <iostream>
#include <map>
using namespace std;
#include <iterator>
int main () 
{
     typedef map<intchar, less<int> > M;
     M m1;

     m1.insert(M::value_type(2,'B'));
     m1.insert(M::value_type(3,'C'));
     m1.insert(M::value_type(1,'A'));

     M::iterator It = m1.begin();
     cout << endl << "m1:" << endl;
     while ( It != m1.end() )
     {
         cout << (*It).first << " - "
              << (*It).second 
              << endl;
         It++;
     }

     // copy constructor
     M m2(m1);
    
     It = m2.begin();
     cout << endl << "m2:" << endl;
     while ( It != m2.end() )
     {
         cout << (*It).first << " - "
              << (*It).second 
              << endl;
         It++;
     }
     
     M m3(m2.begin(),m2.end());

     It = m3.begin();
     cout << endl << "m3:" << endl;
     while ( It != m3.end() )
     {
         cout << (*It).first << " - "
              << (*It).second 
              << endl;
         It++;
     }
     getchar();
     return 0;
}

posted on 2012-04-13 11:51 加文 阅读(151) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理