在 C++ 中 运行 system() 时接收 gnuplot 错误

Receiving Error for gnuplot when running system() in C++

我正在尝试编写一个简单的 C++ 程序来将数据(目前硬编码)写入文件,然后使用我在 MacOS 上随 brew 安装的 gnuplot 将数据显示为图表。

以下是我的代码:

#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.dat");
  myfile << "0 0 0.001\n1 0.25 0.1\n2 0.5 0.05\n3 0.75 0.4";
  myfile.close();
  cout << "Successful Write to file.\n";
  system("gnuplot");
  //system("plot 'example.dat'");
  cout << "\nSuccessful Command Call.";
  return 0;
}

但是,我收到错误消息:

sh: gnuplot: command not found

如能提供解决此问题的任何帮助,我将不胜感激。

刚刚将 /usr/local/bin/gnuplot 替换为 C++ 代码中的 gnuplot,它似乎可以正常工作。非常感谢您的帮助!