C++ 连接字符串what';这是最好的办法吗?

C++ 连接字符串what';这是最好的办法吗?,c++,mysql,C++,Mysql,我有一个在std::string中形成的查询字符串,该查询有4个点,每个点有一个x,y,每个点都是双数据类型 在c中,如何连接字符串以将4个点(8个变量)放入该查询中++ 'MULTIPOINT(16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549)'; 以下是查询的形式: string query = "SELECT * from areas WHERE st_contains(ST_Convex

我有一个在std::string中形成的查询字符串,该查询有4个点,每个点有一个x,y,每个点都是双数据类型

在c中,如何连接字符串以将4个点(8个变量)放入该查询中++

'MULTIPOINT(16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549)';
以下是查询的形式:

string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext('MULTIPOINT(16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549)',4326));";




double x1 = 6.17951, x2 = 6.17951, x3 = 6.17951, x4 = 6.17951;
double y1 = 7.85549, y2 = 7.85549, y3 = 7.85549, y4 = 7.85549;

    /* std::string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext('MULTIPOINT(" 
                    + to_string(x1) + " " + to_string(y1) + ", " 
                    + to_string(x2) + " " + to_string(y2) + ", " 
                    + to_string(x3) + " " + to_string(y3) + ", " 
                    + to_string(x4) + " " + to_string(y4) + "',4326));";
 */

    string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext('MULTIPOINT(6.17951 7.85549, 6.17951 7.85549, 6.17951 7.85549, 6.17951 7.85549)',4326));";

根据您的输入类型,有几个选项

如果您有一个
std::string
,请执行以下操作:

std::string mp = "'MULTIPOINT(16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549)'";
std::string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext(" + mp + ",4326));";
std::string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext('MULTIPOINT(" 
                    + std::to_string(x1) + " " + std::to_string(y1) + ", " 
                    + std::to_string(x2) + " " + std::to_string(y2) + ", " 
                    + std::to_string(x3) + " " + std::to_string(y3) + ", " 
                    + std::to_string(x4) + " " + std::to_string(y4) + ")',4326));";
如果您的输入是双倍的,并且您使用的是C++11,那么您可以这样做:

std::string mp = "'MULTIPOINT(16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549, 16.17951 47.85549)'";
std::string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext(" + mp + ",4326));";
std::string query = "SELECT * from areas WHERE st_contains(ST_ConvexHull(areas.GEOMETRY),st_mpointfromtext('MULTIPOINT(" 
                    + std::to_string(x1) + " " + std::to_string(y1) + ", " 
                    + std::to_string(x2) + " " + std::to_string(y2) + ", " 
                    + std::to_string(x3) + " " + std::to_string(y3) + ", " 
                    + std::to_string(x4) + " " + std::to_string(y4) + ")',4326));";

听起来像你在寻找?我已经用to_字符串执行了你的查询,但它确实返回了整个查询结果,但是如果我硬编码了编辑后的文章中所示的点,它查询的输出在逻辑上是正确的。当类似的事情不起作用时,只需比较两个查询字符串。区别是什么?根本没有区别,这很奇怪。查询1的大小比查询2的大小大1个字节。”)缺少这个