string->char?



  • g++:

    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>
    #include <mysql/mysql.h>
    #include <string>
    #include <unistd.h>
    #include <sstream>
    ...
    global:
    int query_res;
    char query2[500];
    stringstream query;
    ...
    query << "SELECT * FROM db WHERE id > '" << id << "' ORDER BY id";
    query_res = dbquery();
    ...
    
    int dbquery()
    {
    	string query1 = "";
    	query1 = query.str() + '\0';
    	int i = 0;
    	while(query1[i] != '\0')
    	{
    	   query2[i] = query1[i];
    	   i++;
    	}
    	while(i<=500)
    	{
    	   query2[i] = ' ';
    	   i++;
    	}
    	query_res = mysql_query(&my_connection, query2);
    	query.str("");
               int query_res;
    	if (query_res) printf("SELECT error: %s\n", mysql_error(&my_connection));
    	return query_res;
    }
    

    kann mir jemand helfen den string(stream) etwas "schöner" in nen constant char (int mysql_query(MYSQL *mysql, const char *anfrage)) umzuwandeln?

    irgendwie klappt das nur wenn char[500] global ist 😕



  • Mit

    query_res = mysql_query(&my_connection, query.str().c_str());
    

    kannst du dir den ganzen Kopierkram sparen.



  • danke!! 👍


Anmelden zum Antworten