按名称和国家/地区搜索的功能
Function searching by name and country
当我将其更改为按点或其他整数搜索时,它正在工作,但我必须使其按名称和国家/地区搜索。该函数正在检查已经包含数据的数组。
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[]
并使用 ==
。
相关文章:
- 有根的二进制搜索树.保留与其父级的链接
- 在C++中搜索嵌套多映射值
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 二进制搜索树叶数问题
- 为什么二进制搜索在我的测试中不起作用
- 正在尝试重载二进制搜索树分配运算符
- c++binary_search函数排序数组(流行名称搜索)出现问题
- 向量上的线性搜索
- 如何在动态数组上使用搜索函数
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- cmake:添加要搜索头文件的目录
- 使用C++创建特殊的二叉搜索树
- 在C++的字符串中搜索和删除某些字符
- std::unordered_map 搜索算法是如何实现的?
- 使用不变量来确定二分搜索中的边界条件
- 二叉搜索如何比线性搜索更快?
- 按边长度递归搜索图中所有可行路径
- QStackWidget - 按名称搜索
- 在递归二叉搜索树中搜索
- 按名称和国家/地区搜索的功能