I have the following, and no matter what i try a command window is opened and closed again. No plots are shown, no files are written. Anyone who have a solution to use gnupl
Of course, following answer is quite similar to the answer of Nicholas Kinar, the only added point is how to save the .png file properly. Also a couple of suggestions:
"C:Program" is not recognized as an internal or external command....gnuplot doesn't shows any error, it is difficult to spot the exact reason.Following is the complete C++ program which works just fine on Visual Studio 2013 on Windows 8.1
#include
#include
int main()
{
FILE* pipe = _popen("C:/gnuplot/bin/pgnuplot.exe", "w");
if (pipe != NULL)
{
fprintf(pipe, "set term win\n");
fprintf(pipe, "plot(x, sin(x))\n"); //a simple example function
fprintf(pipe, "set term pngcairo\n");
fprintf(pipe, "set output \"myFile.png\"\n" );
fprintf(pipe, "replot\n");
fprintf(pipe, "set term win\n");
fflush(pipe);
}
else puts("Could not open the file\n");
_pclose(pipe);
//system("pause");
return 0;
}