您的位置:首页 > 移动开发 > IOS开发

map的一种替代方案,不会自动排序(转)

2010-01-10 14:23 417 查看



map的一种替代方案,不会自动排序 

  看来只有用vector<   std::pair<std::string,   std::string>   >了  

  ...   

  #include   <vector>   

  #include   <string>   

  #include   <iostream>   

    

  int   main(int   argc,   char**   argv)   

  {   

  using   namespace   std;   

  typedef   pair   <std::string,   std::string>   spair__;   

  typedef   vector<   spair__   >   vector_type;   

  vector_type   svec;   

  svec.push_back(   spair__(   "January",   "2004-01"   )   );   

  svec.push_back(   spair__(   "Feburary",   "2004-02"   )   );   

  svec.push_back(   spair__(   "March",   "2004-03"   )   );   

  svec.push_back(   spair__(   "April",   "2004-04"   )   );   

  svec.push_back(   spair__(   "May",   "2004-05"   )   );   

    

  for   (   vector_type::iterator   it   =   svec.begin();   

  it   !=   svec.end();     

  ++it   )   

  cout   <<   it->first   <<   "     "   <<   it->second   <<   "/n";   

  return   0;   

  }

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息