我有一个小的结构:错误C2664:show_info:无法从 '的char [20]' 转换参数2至“字符
struct price
{
char name[20];
char shop[20];
int pr;
price *next;
};
甲功能不起作用:
void show_info(price *&head, char cur)
{
bool found = 0;
price *temp = new price;
temp->name = cur;
for (price *i=head; i!=NULL; i=i->next)
if (temp == i)
{
cout<< i->shop << i->pr;
found = 1;
}
if (!found)
cout << "The the good with such name is not found";
delete temp;
}
主文件:
int main()
{
price *price_list=NULL;
char inf[20];
list_fill(price_list);
cout << "Info about goods: ";
show_list(price_list); //there is no problem
cout <<"Input goods name you want to know about: ";
cin >> inf;
cout << "The info about good " << inf << show_info(price_list,inf)<<endl;
system("pause");
return 0;
}
我需要修复我的功能,以便它可以正常工作。
如上所述,错误是c2664。
它是'show_info()'还是'show_list()'? – NPE 2014-10-26 20:16:30
erm ...是它的show_info()。我的错。 – Grafit 2014-10-26 20:19:45
可能值得用'std :: string'替换'char [20]'。我看到你正在试图进行某种搜索;通过使用'std :: string'你可以避免麻烦。 – anatolyg 2014-10-26 20:33:44