string & char

cannot convert 'std::string' to 'const char*' for argument '2' to 'int sqlite3_exec(sqlite3*, const char*, int (*)(void*, int, char**, char**), void*, char**)'|


and the code is

1
2
3
4
5
6
7
8
9
10
11
 string name;
        string number;
        cout << "Enter your name : ";
        cin >> name;
        cout<< "Enter numbeer : ";
        cin >> number;
        string s1 = "insert into Contacts(name,number) values(\" ";
        string s2 =" \",\" ";
        string s3 = " \");";
        string s4 = s1 + name + s2 + number +s3;
        rc = sqlite3_exec(db, s4 , callback, 0, &zErrMsg);


this error is on 11

no clue what it says
It says that you have a function that wants a const char* and you're trying to feed it a string.

rc = sqlite3_exec(db, s4 , callback, 0, &zErrMsg);
See that second parameter, s4? That should be a const char*. Not a string.

Look into the string class c_str() function.
try using this in line 11
 
rc = sqlite3_exec(db, s4.c_str() , callback, 0, &zErrMsg);
OOHH!! now I remember Instructor/teacher was saying something like this .
thanks :)


{also trying to comprehend the error msg}
Last edited on
Topic archived. No new replies allowed.