按名称和国家/地区搜索的功能

Function searching by name and country

本文关键字:地区 搜索 功能 国家      更新时间:2023-10-16

当我将其更改为按点或其他整数搜索时,它正在工作,但我必须使其按名称和国家/地区搜索。该函数正在检查已经包含数据的数组。

void search (competitor competitors[], int number)  
{
if(number==0)
{
    cout<<"n Array is empty!!!n";
    return;
}
char country[50];
char name[50];
char choice;
bool flag;
do{
    cout << "nn Enter country: " << endl;
    cin >> country;
    cout << " Enter name: " << endl;
    cin >> name;
    flag = false;
    for(int i=0; i<number; i++)
    {
        if( country==competitors[i].country && name==competitors[i].name)
        {
            count << " Competitor found!" << endl;
        }
    }
    if (flag == false)
    cout << " Want to search again(Y/N)?: ";
    cin >> choice;
}while(choice == 'Y' || choice == 'y');

}

我假设competitors[i].country (name)是一个char[]

不能使用 == 比较char[]数组(这将比较数组的基址,而不是内容),您必须strcmp() .或者,由于这是C++,请使用std::string而不是char[]并使用 ==