jeudi 27 février 2020

error: cannot convert 'std::__cxx11::basic_string

i've tried and fixed bt others comment at stackoverflow, but my program still not working properly

#include <iostream>
#include <windows.h>
#include <mysql.h> //header mysql
#include <sstream>
#include <cstring>
#include <algorithm>

using namespace std;

 int main()
{
int j, count = 0;
char del[] = ".,/;:";
string hadis, hadis1;
MYSQL* conn;
MYSQL_ROW row, row2;
MYSQL_RES* res, res2;
conn = mysql_init(0);
conn = mysql_real_connect(conn, "192.168.43.205", "ibrahim", "hadis", "hadis", 0, NULL, 0);
if(conn)
{
    //int qstate = mysql_query(conn, "SELECT NoHdt, Isi_Arab, Isi_Indonesia, Kategori, Perawi FROM malik ORDER BY id ASC");
    //int qstate = mysql_query(conn, "SELECT NoHdt, Isi_Indonesia FROM malik ORDER BY id ASC");
    int qstate = mysql_query(conn, "SELECT Isi_Indonesia FROM malik");
    if(!qstate)
    {
        res = mysql_store_result(conn);
        while(row = mysql_fetch_row(res))
        {
            hadis = row[0];
            for(unsigned int i=0;i<strlen(del);++i)
            {
                hadis.erase (remove(hadis.begin(), hadis.end(), del[i]), hadis.end());
            }
            for (j=0; hadis[j]; j++)
            {
                if (hadis[j] == ' ')
                {
                    count++;
                    cout<< "-";
                }
                hadis1 = hadis[j];
                cout<<hadis1;
            }
            cout<<"\n";
            int input = mysql_query(conn, "INSERT INTO totalkata_malik(kata,total) VALUES ('"+hadis1+"',1)");  //this is error
            }

        }
            cout<< "\n\nJumlah kata = "<<count+1<<"\n\n";
}

return 0;
}

and i've tried with this code

  std::string query = "INSERT INTO totalkata_malik(kata,total) VALUES 
  ('"+hadis1+"',1)";
        if (mysql_query(conn, query.c_str()))

these code is working and the compiler run well, but the result in my database wasn't suitable the result that i desire, i could input word by word as the result of splitting the string(data from database)

Aucun commentaire:

Enregistrer un commentaire