0

I am struggling with the code from few days can anyone help

std::string str=uri_req1.substr(found+1);
char query[2000];
sprintf(query,"Insert into publish VALUES('%s','NO')",str);

I am getting following warnings and value is not inserted in the tables

warning: cannot pass objects of non-POD type ‘struct std::string’
through ‘...’; call will abort at runtime
warning: format ‘%s’ expects type ‘char*’, but
argument 3 has type ‘int’

other thing I tried was

string query;
query="Insert into publish values('";
query+=str;
query+="','NO')";
  mysql_query(&mysql,query);

but this also never worked kindly help

1
  • It told you it didn't like string but does like char*. Why not just call query.c_str()? Commented Sep 21, 2010 at 5:24

2 Answers 2

4

I'd probably use a stringstream to assemble the string:

std::ostringstream query;

query << "Insert into publish values('" << str << "', 'NO')";
mysql_query(&mysql, query.str().c_str());
Sign up to request clarification or add additional context in comments.

Comments

0

This will surely work ;)

string query;
query="Insert into publish values('";
query+=str; 
query+="','NO')"; 
mysql_query(&mysql,query.c_str());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.