简体   繁体   中英

How to link gnuplot to c++

What would be the code to plot a simple sin x graph in c++? i tried this...

#include<iostream>
#include<fstream>
#include<stdio.h>


using namespace std;

int main()
{
  FILE *gnuplotPipe = popen("C:\\Program Files\\gnuplot\\bin\\wgnuplot -persist","w");


if (gnuplotPipe) {

fprintf(gnuplotPipe, "plot sin(x)");
fflush(gnuplotPipe);

}
}

but i get this error.... c:\\Program is not recognized as an internal or external command

Do i have to configur linker settings or anything else?? Please help. Thanks in advance :)

You need quotes around the file name because it contains a space.

popen("\"C:\\Program Files\\gnuplot\\bin\\wgnuplot\" -persist","w");

You have one set of quotes because it's a string literal, but that string has to contain more quotes because of the space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM