1、如果要发送结构体中的数据,那么struct中不能使用char*或者string类,因为char*本质上是指针,而指针是通过操作地址来查找数据的,所以服务器接收到的数据只有4个字节长(因为在32为系统中指针大小为4);而string类,服务器会不知道接收的数据大小为多少,会报错!

2char*转为string :       stringstr;

                                            str =”hello”;

        

                                            char s[10];

                                            strcpy(s,str.c_str());//str.c_str()string转换成char*类型

     string转为char* string str

               str.c_str;

3、将读取到的sql_row放到string字符串中,因为string有自动拼接的特性

                result =mysql_store_result(&myCont);//获取结果集

                sql_row =mysql_fetch_row(result);//获取本行数据

                string str;

                for (int i = 0; i< 7; i++)

                {

                          str +=sql_row[i];//将读取到的数据全部放入string字符串

                }


版权声明:本文为cool_saddly原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/cool_saddly/article/details/79182620