我正在尝试使用c ++和mysql创建登录系统,但出现此错误

问题描述 投票:0回答:1

我正在尝试使用C ++和mysql创建登录系统,但出现此错误“类型为” String“的参数与类型为” const char *“的参数不兼容”这是我的代码

    MYSQL* conn;
    MYSQL_ROW row;
    MYSQL_RES *res;
    conn = mysql_init(0);
    conn = mysql_real_connect(conn, "localhost", "root", "root", "app", 3306, NULL, 0);
    if (conn) {
        String ^name = (this->name->Text);
        String ^ password = (this->password->Text);
                        string query = "select name,password from login where name ='" + name + "' and password ='" + password + "' ";

        const char* q = query.c_str();
        int qstate = mysql_query(conn, q ");
        if (!qstate) {
            res = mysql_store_result(conn);
        while (row = mysql_fetch_row(res)); {

            MessageBox::Show("exist ");

        }

        }
        else {
            MessageBox::Show("user not exist");
        }
    }
    else {
        MessageBox::Show("Error Data base not connected ");

    }

}

感谢您的帮助

c++ mysql c++-cli
1个回答
0
投票

C ++区分字符串和const char *。后者称为C字符串(因为C没有字符串的抽象数据类型)。您可以使用c_str函数将字符串转换为const char *:

std::string str;
const char * c = str.c_str();
© www.soinside.com 2019 - 2024. All rights reserved.