我在用着gcc
在代码块上,我想编写一个使用记录数组的函数。
但是我不断收到错误:
invalid conversion from 'int' to 'const char*'
代码:
#include <iostream>
#include <string>
using namespace std;
struct rendeles {
string nev;
int mennyiseg;
};
struct teaceg {
string nev;
int mennyiseg;
};
int szam;
struct rendeles rendelt [100];
struct teaceg cegek [100];
int h;
int hanyadikceg (string cegnev)
{
for (int i=0;i<szam;i++)
{
if (cegek[i].nev==cegnev)
{
return i;
}
}
return -1;
}
int main()
{
cout << "Hány db rendelés lesz összesen?";
cin >> szam;
if (szam > 100)
{
cout << "Hiba: túl nagy a rendelések száma! (100 a maximum)";
return -1;
}
for (int i=0;i<szam;i++)
{
cout << "A(z) " << i+1 <<". cég neve:";
cin >> rendelt[i].nev;
cout << "A(z) " << i+1 <<". rendelés mennyisége:";
cin >> rendelt[i].mennyiseg;
}
cout << endl;
h = hanyadikceg('Lipton'); //the problem is in this line
cout << "Hanyadik cég a xyz:" << h;
for (int i=0;i<szam;i++)
{
cout << "A(z) " << i+1 << ". rendelés: " << rendelt[i].nev << " " << rendelt[i].mennyiseg << endl;
}
return 0;
}
是什么原因导致此错误?
您需要使用双引号 ("
) 用于字符串文字,而不是单引号 ('
).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)