二。容器操作

二。容器操作

 

1: mutimap

 

应用:把数据库的表结构转化为树结构,并层级菜单动态显示

 

eg:

 

abd                  d 

abd             b {  e  

acf   -->   a {      

acg             c { f

acfh                g

                    h

 

---先把表信息存到内存结构里面-----

 

数据类型:

 

    #include<map>                //mutimap 头文件

    #include <utility>           //pair头文件

 

    multimap<AnsiString , AnsiString>          mp_name;                  

    typedef multimap<AnsiString , AnsiString>::iterator mp_it;

    typedef pair<mp_it,mp_it >                 pos_Pair;

 

    for( int i = 0; i< rowcount ;i++)  //遍历行

    {

        for( int j = 1; i< fieldcount ;i++)   //遍历列 

       {

             strFirst = table->Fields[i-1]->AsString;

             strSecond= table->Fields->Fields[i]->AsString;

             pos_Pair pos_first;

             pos_first = mp_city.equal_range(strFirst) ;

             while(pos_first.first!=pos_first.second )

             {

                  if( strSecond == pos_first.first->second)

                      break;

                  else

                      ++pos_first.first;

             }

             if(pos_first.first==pos_first.second)

             {

                  mp_name.insert(make_pair(strFirst, strSecond));

             }       

       }

    }

 

----------双击按钮,弹出层级菜单---------

void __fastcall TMainForm::BitBtn_w1Click(TObject *Sender)

{

      PopupMenu(Sender) ;

      POINT point1;

      GetCursorPos(&point1);      

      PopupMenu_Window->Popup(point1.x,point1.y);

 

}

 

TPopupMenu  PopupMenu (onPopup 事件)

 

void __fastcall TMainForm::PopupMenuPopup(TObject *Sender)

{

    PopupMenu->Items->Clear();

    TMenuItem *NewItem ;

    pos_Pair  pos_city;

    pos_city = mp_city.equal_range(CurrentUser) ;

    while(pos_name.first!=pos_name.second )

    {

         NewItem = new  TMenuItem(PopupMenu);

         NewItem->Caption= pos_city.first->second;

         PopupMenu->Items->Add(NewItem);  

         createAreaItems(Sender,NewItem);  //生成下级菜单

         ++pos_city.first;

    }

    NewItem = NULL;

}

 

2: list

 

#include <list>

 

list<unsigned char> m_listData;

char *pBuffer;

 

for (int i=0; m_listData.size();i++)

{

    *(pBuffer+i) = m_listData.front();

    m_listData.pop_front();

 

}

//m_listData.clear();

// m_listData.push_back(*(pData+i));

 

3: vector

 

 赋初值:

 vector<String> aa;

 vector<String> bb(aa)或

 vector<String> bb(aa)//vector可以直接等(值拷贝) 数组不能:a[5]=b[5]错误

 vector <AnsiString> ::iterator iter =  vec_AllPicture[nIndex].begin();

 while(iter!= vec_AllPicture[nIndex].end())

 { 

     //do sth

 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值