gnuplot c++;通过管道的接口-无法打开wgnuplot 我试图从我的C++程序中实时地绘制我的图形,我已经安装了GnUrPro 4.6,并且能够打开GnAppExt.EXE和绘图图。但是我不能通过管道打开应用程序。这是我使用的代码 #include <stdio.h> #include <stdlib.h> int main() { FILE* gp; char *path = "C:\Program Files\gnuplot\bin\wgnuplot"; #ifdef WIN32 gp = _popen("gnuplot -persist", "w"); #else gp = _popen(path, "w"); #endif if (gp == NULL) return -1; fprintf(gp, "set isosample 100\n"); fprintf(gp, "min=-1\n"); fprintf(gp, "max=1\n"); fprintf(gp, "pi=3.141592\n"); fprintf(gp, "set hidden3d\n"); fprintf(gp, "set pm3d\n"); fprintf(gp, "set contour\n"); fprintf(gp, "splot [min:max] [min:max] x*x+2*y*y-0.3*cos(3*pi*x)-0.4*cos(4*pi*y)+0.7\n"); fprintf(gp, "pause -1\n"); return 0; } #包括 #包括 int main() { 文件*gp; char*path=“C:\Program Files\gnuplot\bin\wgnuplot”; #ifdef WIN32 gp=_popen(“gnuplot-persist”,“w”); #否则 gp=_popen(路径,“w”); #恩迪夫 if(gp==NULL) 返回-1; fprintf(gp,“设置isosample 100\n”); fprintf(gp,“min=-1\n”); fprintf(gp,“max=1\n”); fprintf(gp,“pi=3.141592\n”); fprintf(gp,“设置hidden3d\n”); fprintf(gp,“设置pm3d\n”); fprintf(gp,“设置轮廓”\n); fprintf(gp,“splot[min:max][min:max]x*x+2*y*y-0.3*cos(3*pi*x)-0.4*cos(4*pi*y)+0.7\n”); fprintf(gp,“暂停-1\n”); 返回0; }

gnuplot c++;通过管道的接口-无法打开wgnuplot 我试图从我的C++程序中实时地绘制我的图形,我已经安装了GnUrPro 4.6,并且能够打开GnAppExt.EXE和绘图图。但是我不能通过管道打开应用程序。这是我使用的代码 #include <stdio.h> #include <stdlib.h> int main() { FILE* gp; char *path = "C:\Program Files\gnuplot\bin\wgnuplot"; #ifdef WIN32 gp = _popen("gnuplot -persist", "w"); #else gp = _popen(path, "w"); #endif if (gp == NULL) return -1; fprintf(gp, "set isosample 100\n"); fprintf(gp, "min=-1\n"); fprintf(gp, "max=1\n"); fprintf(gp, "pi=3.141592\n"); fprintf(gp, "set hidden3d\n"); fprintf(gp, "set pm3d\n"); fprintf(gp, "set contour\n"); fprintf(gp, "splot [min:max] [min:max] x*x+2*y*y-0.3*cos(3*pi*x)-0.4*cos(4*pi*y)+0.7\n"); fprintf(gp, "pause -1\n"); return 0; } #包括 #包括 int main() { 文件*gp; char*path=“C:\Program Files\gnuplot\bin\wgnuplot”; #ifdef WIN32 gp=_popen(“gnuplot-persist”,“w”); #否则 gp=_popen(路径,“w”); #恩迪夫 if(gp==NULL) 返回-1; fprintf(gp,“设置isosample 100\n”); fprintf(gp,“min=-1\n”); fprintf(gp,“max=1\n”); fprintf(gp,“pi=3.141592\n”); fprintf(gp,“设置hidden3d\n”); fprintf(gp,“设置pm3d\n”); fprintf(gp,“设置轮廓”\n); fprintf(gp,“splot[min:max][min:max]x*x+2*y*y-0.3*cos(3*pi*x)-0.4*cos(4*pi*y)+0.7\n”); fprintf(gp,“暂停-1\n”); 返回0; },c++,gnuplot,C++,Gnuplot,我已经设置了环境变量,得到了以下错误。 c:程序\未被识别为内部或外部命令和可操作程序或批处理文件 我尝试用相同的路径运行exe。但它没有打开。这是因为cmd提示符中可以给出的字符串的最大长度 请给出你有价值的建议 谢谢反斜杠路径分隔符必须转义(或替换为斜杠): 您应该将_popen函数编写为 gp=_popen(“E:\\myprograms\\ProgramFiles\\libraries\\Gnuplot\\bin\\Gnuplot-persist”,“w”) 并可能通过这种方式调用相应的

我已经设置了环境变量,得到了以下错误。 c:程序\未被识别为内部或外部命令和可操作程序或批处理文件

我尝试用相同的路径运行exe。但它没有打开。这是因为cmd提示符中可以给出的字符串的最大长度

请给出你有价值的建议


谢谢

反斜杠路径分隔符必须转义(或替换为斜杠):


您应该将_popen函数编写为

gp=_popen(“E:\\myprograms\\ProgramFiles\\libraries\\Gnuplot\\bin\\Gnuplot-persist”,“w”)

并可能通过这种方式调用相应的数据文件

fprintf(gp,“splot”C:\\\\Users\\\\username\\\\Documents\\\\Visual Studio 2012\\\\Projects\\\\laplace等式\\\\laplace.dat\“\n”)

您可以使用它来绘制图形

这个小片段解决了您的问题(test1.cpp):

这给

您的
#ifdef
构造很奇怪,考虑到您已将其设置为仅在不使用Windows的情况下使用非常多的仅Windows路径。好的。。我已经下载了一个特定于windows的库并使用了它。@Zack是否还有其他用于此目的的好库。。我使用ggplot2在R中进行所有绘图。我不知道从外部程序控制它是否可行,但我预计它至少会像你现在尝试做的那样麻烦。对不起,我帮不上什么忙了。谢谢。。现在gnuplot打开了,但是命令没有写入其中。没有出现绘图。
char *path = "C:\\Program Files\\gnuplot\\bin\\wgnuplot";
#include "gnuplot_i.hpp" 

int main()
{
   Gnuplot gp;
   gp.cmd("set isosample 100\n");
   gp.cmd("min=-1\n");
   gp.cmd("max=1\n");
   gp.cmd("pi=3.141592\n");
   gp.cmd("set hidden3d\n");
   gp.cmd("set pm3d\n");
   gp.cmd("set contour\n");
   gp.cmd("splot [min:max] [min:max] x*x+2*y*y-0.3*cos(3*pi*x)-0.4*cos(4*pi*y)+0.7\n");
   gp.cmd("pause -1\n");


   std::cout << std::endl << "Press ENTER to continue..." << std::endl;
   std::cin.clear();
   std::cin.ignore(std::cin.rdbuf()->in_avail());
   std::cin.get();

   return 0;
}
g++ test1.cpp && ./a.out