问题描述
我想做的是, 首先,我想调用gnuplot程序并绘制函数。但是我是通过使用popen函数做到的。
然后,我看到绘制的图,并输入一个值以同时计算问题的解决方案。(我失败了。)
问题是打开gnuplot程序后程序无法继续运行。
使用popen后如何继续运行c ++代码?
这是我编写的代码
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <assert.h>
#include <cstring>
using namespace std;
//const char func1[30] = "(10*x)*sin(x*100)";
void plotFunction(char function[50],double x_min,double x_max);
char func1[30] = "sin(3*x)";
char func2[50] = "sinh(x)";
int main()
{
plotFunction(func1,0.0,6.3);
plotFunction(func2,-3,3);
cout << "process finished" << endl;
return 0;
}
void plotFunction(char function[50],double x_max)
{
char range[100];
char min[10]; char max[10];
sprintf(min,"%f",x_min);
sprintf(max,x_max);
strcpy(range,"set xrange [");
strcat(range,min);
strcat(range,":");
strcat(range,max);
strcat(range,"]\n");
char plot[200];
strcpy(plot,"plot ");
strcat(plot,function);
strcat(plot,"\n");
FILE* plotHandle = NULL;
if (plotHandle == NULL) {
plotHandle = _popen("C:\\Program\" \"Files\\gnuplot\\bin\\gnuplot.exe -continue","w");
assert(plotHandle != NULL);
}
fprintf(plotHandle,"set terminal wxt\n");
fprintf(plotHandle,"set xlabel \"X\"\n");
fprintf(plotHandle,"set ylabel \"Y\"\n");
fprintf(plotHandle,range);
fprintf(plotHandle,"set grid\n");
fprintf(plotHandle,"plot (10*x)*sin(x*100)\n");
fprintf(plotHandle,plot);
//fflush(plotHandle);
//_pclose(plotHandle);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)