使用字符串类的 find 方法,我在查询中没有得到正确的结果。这是我的代码
int main()
{
string phoneData;
string name;
string phoneNumbers[51];
ifstream inputFile;
inputFile.open("phonebook");
int i = 0;
while (getline(inputFile, phoneData))
{
phoneNumbers[i] = phoneData;
i++;
}
cout << "Enter a name or partial name to search for: ";
getline(cin, name);
cout << endl << "Here are the results of the search: " << endl;
for(int i =0;i<50;i++)
{
if (name.find(phoneNumbers[i]) == 0)
cout << phoneNumbers[i] << endl;
}
inputFile.close();
return 0;
}