Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid conversion from 'int' to 'const char*' [duplicate]

Tags:

c++

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?

like image 893
GregT Avatar asked Mar 14 '12 13:03

GregT


1 Answers

You need to use double-quotes (") for string literals, not single-quotes (').

like image 88
Oliver Charlesworth Avatar answered Sep 27 '22 18:09

Oliver Charlesworth