Here I’m trying to concatenate variables(int and char) by insertQuery,
but I’m getting error, My error is error: invalid operands of types ‘const char*’ and
‘const char [2]’ to binary ‘operator+’
Guys Please Guide me where I’m wrong..
**string insertQuery= "insert into items (user_id,session_id,user_sessionname,buffer)values("
+ user + "," + session + ",'" + usrname + "','" + buff + "')";
sqlite3_stmt *insertStmt;
cout << "Creating Insert Statement" << endl;
sqlite3_prepare(db, insertQuery.c_str(), insertQuery.size(), &insertStmt, NULL);
cout << "Stepping Insert Statement" << endl;
if (sqlite3_step(insertStmt) != SQLITE_DONE) cout << "Didn't Insert Item!" << endl;**
(Assuming null terminated
char*or null terminatedchar[])Recommend using a
std::ostringstream(#include <sstream>) to construct the SQL query:It would also be possible by creating temporary
std::stringobjects in the concatenation sequence:If a
char*orchar[]is not null terminated you can inform thestd::stringconstructor how long it is: