如何使用 gnuplot-iostream.h 读取C++中的数据文件

How can I use gnuplot-iostream.h to read a data file in C++?

本文关键字:数据 文件 C++ 读取 何使用 gnuplot-iostream      更新时间:2023-10-16

我有这个功能:

#include "gnuplot-iostream.h"
void DataParser::histogramPlot(const char* filename) {
    Gnuplot gp("tee plot.gp | gnuplot -persist");
    gp << "set boxwidth 0.5n";
    gp << "set style fill solidn";
    gp << "plot " << filename << " using 1:3:xtic(2) with boxesn";
}

但是当我打电话时

 DataParser::histogramPlot("data1.xml")

它将此error扔到第 gp << "plot " << filename << " using 1:3:xtic(2) with boxesn";

 line 0: undefined variable: data1
 pclose returned error

我尝试将"data1.xml"与我的主项目文件夹和可执行文件一起放置。gnuplot 使用 gp<< 在哪里运行其命令?

我犯了一个愚蠢的错误[=

我忘了在文件名 gp 字符串流中添加引号"

...
    gp << "plot "" << filename << "" using 1:2:xtic(2) with boxesn";
}