Messy strings

S

saneman

I am trying to call gnuplot from C++. I have to make a system call
containing the command and path to a data file:

std::string path_to_data = "c:\\data.txt";
std::string gnuplot = "wgnuplot.exe";
std::string gnuplot_call = gnuplot + " " + path_to_data;
system(&gnuplot_call[0]);

But system wants a char*. Is there anyway to make the above more
simple/readable?
 
I

Ian Collins

saneman said:
I am trying to call gnuplot from C++. I have to make a system call
containing the command and path to a data file:

std::string path_to_data = "c:\\data.txt";
std::string gnuplot = "wgnuplot.exe";
std::string gnuplot_call = gnuplot + " " + path_to_data;
system(&gnuplot_call[0]);

But system wants a char*. Is there anyway to make the above more
simple/readable?
system() expects a const char*, so you should use gnuplot_call.c_str().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,927
Members
47,469
Latest member
benny001

Latest Threads

Top