入门计划->学用stl std::map

C++:一种比较流行的强大功能面向对象编程语言,应用和前景都很广阔。

stl:C++标准模板库,功能极其强大,将其完全掌握后C++编程会相当容易。

map:一种关系式容器,可以根据关键字匹配多种数据。

string:"~!@#$%^&*()_+",这样的东东就是。

以下程序代码将简单演示如何通过名称(string)关键字匹配id(int),由于程式(程序,受网上资料的影响,偶也开始想把程序说成程式,废话)太简单,没有写注释,对于想入门的朋友将代码看明白可以自己举一反三就算学会一招了:)高手请跳过。

程序在以下环境顺利测试通过:

WIN2K+VC6

RedHat Linux 7.2 + gcc(g++)2.96

--源程序--

 disable

  
  

 
  std;

 strmap1

     stdmapstdstring,  type_map;
     type_mapiterator type_iter;

    type_map    mm;
    type_iter   it;
             id;


    strmap1  itNULL, id
    
        
        id  ;
        mm  id;
        mm  id;
        mm  id;
    

     find  s
    
        cout    s  endl;
         ret  ;
        it  mm.finds;
         mm.end  it 
            ret  itsecond;
            cout  s    ret  endl;
          
            cout    s    endl;
        
         ret;
    

     insert  s
    
        cout    s  endl;
         ret  id;
        mm.inserttype_mapvalue_types, ret;
        
         ret;
    

     remove  s
    
        cout    s  endl;
        mm.erases;
    
;

 main argc,  argv

    cout    endl;
    strmap1 o;

    cout  endl;
    o.find;
    
    cout  endl;
    o.find;
    
    cout  endl;
    o.find;
    o.find;

    cout  endl;
    o.insert;
    o.remove;
    o.remove;
    
    cout  endl;
    o.find;
    o.find;
    o.find;
    
    cout  endl;
    cout    endl;
     ;
 

--输出结果--
(strmap1)string map 1(simple use std::map)
find i
i's id is 1
find she
can't find she's id
find you
you's id is 2
find he
he's id is 3
insert she
remove you
remove he
find you
can't find you's id
find he
can't find he's id
find she
she's id is 4
haha~~~now only i and she

你可能感兴趣的:(入门计划->学用stl std::map)