1
有人可以舉例說明如何部分名稱搜索或使搜索不區分大小寫。我輸入這些函數來搜索姓氏,但我想知道如何部分名稱搜索/不區分大小寫。謝謝部分名稱搜索
int Search()
{
for(int i = 0 ; i < Size ; i++)
if (Target == List[i].LastName)
return i;
return -1;
}
void LookUp_Student()
{
string Target;
int Index;
cout << "\nEnter a name to search for (Last Name): ";
getline(cin,Target);
Index = Search(List,Size,Target);
if (Index == -1)
cout << Target <<" is not on the list.\n" ;
else
Print_Search(List[Index]);
}
你可能會發現這個問題和答案有幫助http://stackoverflow.com/questions/313970/stl-string-to-lower-case至少對於不區分大小寫的方面 – mathematician1975
使用toupper(或tolower)使其不區分大小寫。然後使用find來搜索字符串中的子字符串。 –