I am using Signal query to catch errors in my c programming: in the program user has to enter a database name and i check the database if it does not exists I have to return proper error message:
std::string database_name;
std::cin<<database_name;
if(!exists(database_name)){
query="SIGNAL SQLSTATE '42000' SET MYSQL_ERRNO='1049', MESSAGE_TEXT = 'Unknown database';";
}
how can I print the database_name variable after Unknown database?
CodePudding user response:
You can format the string using
query = std::format( "... MESSAGE_TEXT = 'Unknown database {}'", database_name );
This will replace {}
with the first string argument (database_name
)
Or you could just append the variable into it directly, like
query = "... MESSAGE_TEXT = 'Unknown database " database_name "'";