//定义一个函数,按学号进行匹配
TBool MatchNum(const TStudent& aStu1, const TStudent& aStu2)
{
if (aStu1.iNum == aStu2.iNum)
{
return ETrue;
}
else EFalse;
}
//在TestArray()函数中添加的代码如下:
TIdentityRelation<TStudent> matcher(MatchNum);
TInt index = KErrNotFound; // 初始为没有找到匹配的数据
index = stuRArray.Find(TStudent(_L("Green"),2,5),matcher);
if (index != KErrNotFound)
{
console->Printf(KString1,&stuRArray[index].iName,stuRArray[index].iNum,stuRArray[index].iMark);
}
else
{
console->Printf(_L("None is found....."));
}
运行的结果如图:找到学号为2的学生的数据