lundi 23 mars 2020

terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc, this application has requested the runtime to terminated

i made my program using codeblock with c++11, and idk what should i do this for my thesis, it kinda an honor for me to get your help thank you

this my code

//Script pecah kata dan hitung total kata dengan c++

#include <iostream>
#include <windows.h>
#include <mysql.h> //header mysql
#include <sstream>  //merubah semua tipe data yang diinputkan user ke string
#include <algorithm> //untuk menggunakan fungsi begin, end
#include <regex>

using namespace std;

int main()
{
string hadis, hadis1;
MYSQL* conn;
MYSQL_ROW row; // return data as array of strings
MYSQL_RES* res;
conn = mysql_init(0);
conn = mysql_real_connect(conn, "192.168.43.205", "ibrahim", "hadis", "hadis", 0, NULL, 0);
//hp harus sesuai dengan ip address yang sedang digunakan
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];
            regex reg("[^\\w]+");
            hadis = regex_replace(hadis, reg, " ");
            istringstream iss(hadis);
            vector<string> result;
            for(string s;iss>>s;)
                result.push_back(s);
            int n=result.size();
            int i;
            for( i=0;i<n;i++)
            cout<<result[i]<<endl;
            string query = "INSERT INTO totalkata_malik(kata,total) VALUES ('"+result[i]+"',1)";
                if (mysql_query(conn, query.c_str()))
                {
                    cout<< "";
                }
            //cout << hadis <<"\n\n";
        }
            //string s1="split on     whitespace";


        }
}
return 0;
}

i dont know what should i do with this warning, please help me, i red some preference and still cant solve this problem

Aucun commentaire:

Enregistrer un commentaire