1

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

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 << "\n\n 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');

}

4

1 回答 1

2

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

您不能char[]使用比较数组==(将比较数组的基地址,而不是内容),您必须使用strcmp(). 或者,因为这是 C++,所以使用std::string代替char[]和使用==.

于 2012-05-11T13:11:27.810 回答