C++ 如何在xdool命令中使用变量

C++ 如何在xdool命令中使用变量,c++,opencv,xdotool,C++,Opencv,Xdotool,我有以下代码。当我执行代码时,我的鼠标指针移动到0坐标。我需要将光标移动到x1 y1位置。x1 y1的值是整数 int x1,y1; for(int i=0; i<nomdef; i++) { if(defectArray[i].depth > 40 ) { con=con+1;

我有以下代码。当我执行代码时,我的鼠标指针移动到0坐标。我需要将光标移动到x1 y1位置。x1 y1的值是整数

int x1,y1;
                for(int i=0; i<nomdef; i++)  
                {
                    if(defectArray[i].depth > 40 )
                    {
                        con=con+1;
                        if(con==1)
                        {
                            x1=(defectArray[i].depth_point)->x;
                y1=(defectArray[i].depth_point)->y;
                        }
                        cvLine(src, *(defectArray[i].start), *(defectArray[i].depth_point),CV_RGB(255,255,0),1, CV_AA, 0 );  
                        cvCircle( src, *(defectArray[i].depth_point), 5, CV_RGB(0,0,255), 2, 8,0);                              cvDrawContours(src,defects,CV_RGB(0,0,0),CV_RGB(255,0,0),-1,CV_FILLED,8);

                    }
                }system("xdotool mousemove x1 y1");
intx1,y1;
对于(int i=0;i 40)
{
con=con+1;
如果(con==1)
{
x1=(缺陷阵列[i]。深度_点)->x;
y1=(缺陷阵列[i]。深度_点)->y;
}
cvLine(src,*(缺陷阵列[i].开始),*(缺陷阵列[i].深度点),CV_RGB(255255,0),1,CV_AA,0);
CV圆(src,*(缺陷阵列[i]。深度点),5,CV_RGB(0,0255),2,8,0);CV绘制轮廓(src,缺陷,CV_RGB(0,0,0),CV_RGB(255,0,0),-1,CV_填充,8);
}
}系统(“xdotool mousemove x1 y1”);
<代码> > p>这是一个C++程序(不是BASH或任何类似的高级语言)。C/C++字符串常量中没有变量调用/替换

因此,系统调用执行您编写的操作:调用
“xdoool mousemove x1 y1”
(不需要像您预期的那样替换x1和y1)

相反,您必须格式化字符串,例如使用

将以下内容添加到文件开始:

#include <string>
#include <sstream>
#包括
#包括
将代码的最后一行更改为:

std::ostringstream ossCmd;
ossCmd << "xdotool mousemove " << x1 << ' ' << y1;
#if 1 // EXPLICIT:
std::string cmd = ossCmd.str();
system(cmd.c_str());
#else // COMBINED:
system(ossCmd.str().c_str());
#endif // 1
std::ostringstream ossCmd;
ossCmd