I'm using gcc
on codeblocks and I'd like to write a function that uses an array of records.
However I keep getting the error:
invalid conversion from 'int' to 'const char*'
The code:
#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;
}
What causes this error?
You need to use double-quotes ("
) for string literals, not single-quotes ('
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With