试图为我的向量定义一个查找函数,因为该向量包含多个数据;这是一个结构如何定义查找功能?
我是在一个ID的输入,并正尝试搜索,在我的表,找到它的索引(如果该ID已经存在)
所以,我必须声明这里的向量:
vector<Employee> Table;
vector<Employee>::iterator It;
vector<Employee>::iterator find_It;
//Table has these values
//Table.ID, Table.ch1, Table.ch2
而且我想在这里找到ID:
cin >> update_ID;
find_It = find(Table.begin(), Table.end(), update_ID);
会不会有一种方法可以做到与变量UPDATE_ID的发现?
我试着这样做:
find_It = find(Table.begin(), Table.end(), (*It).update_ID;
但显然我的矢量员工没有名为UPDATE_ID
我想做的是创造我自己的查找功能的另一种选择,即数据构件我对如何界定
有点困惑我想返回的ID的索引,其中,Table.ID = UPDATE_ID
我该怎么把为t他返回类型和值参数?它是
returntype find(Iterator, Iterator, update ID)
{
for (vector<Employee>::iterator myit = Table.begin(), Table.end(), myit++)
{
if update_ID == Table.ID
{
return myit;
}
}
return myit
}
当Table是一个向量时,“Table.ID”是什么意思? “ID”是什么类型? –