二。容器操作
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
}