Whiteflags has the right of it. Use a string stream. I would actually make query a string stream, and call .str().c_str() when you pass it to mysql_query, but it hardly matters.