Symbian 中的动态数组 CArrayX
2010-08-31 00:12:00 来源:WEB开发网console->Printf(_L("Press any key to continue "));
console->Getch();
//以姓名方式查找
console->Printf(_L("Find student by name "));
//建立主键,对于不同类型的CArray有不同的主键类型
//_FOFF(c,f)宏来取得类中字段的偏移量
TKeyArrayFix nameKey(_FOFF(TStudent,iSName), ECmpNormal);
TInt findPos;
TStudent S(StuName1,0,0);
console->Getch();
if(StuArrayFlat->Find(S, nameKey, findPos) != KErrNotFound)
{
//查找对象是S,按ECmpNormal格式
console->Printf(_L("findPos is %d "),findPos);
console->Printf((*StuArrayFlat)[findPos].iSName);//直接引用findPos的值,有的书上写findPos-1,这是错误的!
}
console->Printf(KRETURN);
console->Printf(_L("Press any key to continue "));
console->Getch();
//以成绩方式排序
TKeyArrayFix scoreKey(_FOFF(TStudent,iScore), ECmpTInt32);
User::LeaveIfError(StuArrayFlat->Sort(scoreKey));
for(i=0;i
{
console->Printf(_L("name is "));
console->Printf((*StuArrayFlat)[i].iSName);
console->Printf(KRETURN);
console->Printf(KFORMAT2,(*StuArrayFlat)[i].iSNo);
console->Printf(KRETURN);
console->Printf(KFORMAT3,(*StuArrayFlat)[i].iScore);
console->Printf(KRETURN);
}
CleanupStack::PopAndDestroy();
}
更多精彩
赞助商链接