473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Messy strings

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?
Aug 9 '08 #1
2 1227
saneman wrote:
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().

--
Ian Collins.
Aug 9 '08 #2
In article <6g************@mid.individual.net>, Ian Collins
<ia******@hotmail.comwrote:
saneman wrote:
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().
More importantly, it wants a nul-terminated string, which &gnuplot_call[0]
is not; only by bad luck would the undefined access past the end be a nul
character. c_str() is the only correct solution of the two above.
Aug 9 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
72
by: Herbert | last post by:
I'm still relativey new to stylesheets, so I'm hoping that the way I'm going about things can be seriously improved upon, i.e . I just haven't undersood something obvious about the 'cascading'...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
25
by: Rainmaker | last post by:
Hi, Can anyone tell me an efficient algorithm to sort an array of strings? Keep in mind that this array is HUGE and so the algorithm should me efficient enough to deal with it. Thanks
2
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
95
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ...
0
by: Paul McNett | last post by:
I administer email for a few clients of mine, using Postfix. One of the policies that is in place is SPF-checking, and rejecting messages accordingly. This has been working well for months. ...
0
by: carlwuhwdmckay | last post by:
cabbage patch kids messy face doll http://cracks.00bp.com F R E E
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.