C++ 使用system()与Gnuplot一起打印会导致错误:无法读取文件

C++ 使用system()与Gnuplot一起打印会导致错误:无法读取文件,c++,gnuplot,C++,Gnuplot,我试图通过system()在gnu绘图中显示我的数据。 我将一些示例值写入文件,然后尝试使用gnuplot显示它们 以下是我编写测试数据的方式: void Dataset::writeDataSetToFile(){ QString filename="/Users/rogerwilco/Desktop/test/data.txt"; QFile file(filename); if(file.open(QIODevice::WriteOnly)) {

我试图通过system()在gnu绘图中显示我的数据。 我将一些示例值写入文件,然后尝试使用gnuplot显示它们

以下是我编写测试数据的方式:

void Dataset::writeDataSetToFile(){
    QString filename="/Users/rogerwilco/Desktop/test/data.txt";
    QFile file(filename);
    if(file.open(QIODevice::WriteOnly))
    {
        QTextStream stream (&file);
        stream << "1" << endl << "9" << endl << "15"<< endl;

    }
    file.close();

}
我收到此错误消息:

“/Users/rogerwilco/Desktop/test/plotter”,第22行:警告:跳过不可读的文件“data.txt”“/Users/rogerwilco/Desktop/test/plotter”,第22行:绘图中无数据

gnuplot的脚本如下所示:

reset
n=100 #number of intervals
max=100.0 #max value
min=0.0 #min value
width=(max-min)/n #interval width
#function used to map a value to the intervals
hist(x,width)=width*floor(x/width)+width/2.0
#set term png #output terminal and file
set output "histogram.png"
set xrange [min:max]
set yrange [0:]
#to put an empty boundary around the
#data inside an autoscaled graph.
set offset graph 0.05,0.05,0.05,0.0
set xtics min,(max-min)/5,max
set boxwidth width*0.9
set style fill solid 0.5 #fillstyle
set tics out nomirror
set xlabel "x"
set ylabel "Frequency"
#count and plot
plot "data.txt" u (hist($1,width)):(1.0) smooth freq w boxes lc rgb"green" notitle
带有错误的第22行是最后一行。 但是,如果我自己使用外壳

gnuplot 'plotter'
它起作用了

为什么在我将命令手动输入到终端时,而在我通过system()输入命令时,它不起作用

系统:

  • Qt 5.3.2
  • Mac OS X 10.9.5
  • 通过自制的gnuplot 4.6.6
  • AquaTerm 1.1.1 通过自制的叮当64位

我需要在最后一行添加整个路径:

plot”/Users/rogerwilco/Desktop/test/data.txt“u(hist($1,width)):(1.0)平滑频率w框lc rgb“绿色”notitle


(应该感谢Galik和Chris Stratton让我走上了正确的道路)

Galik,谢谢你的建议。你是对的。我需要在最后一行添加整个路径:plot“/Users/rogerwilco/Desktop/test/data.txt”u(hist($1,width)):(1.0)smooth freq w Box lc rgb“green”notitle。如果你事后再考虑,这是很合乎逻辑的…:-DDo您想写答案以便将其标记为完成吗?只是一个提示:gnuplot知道命令
pwd
。所以,如果有这样的问题,pwd可以帮助调试。@ChrisStratton请将此作为答案添加。@ChrisStratton别忘了发布您的答案。。。。
gnuplot 'plotter'