I am using the concept of pipes in a c++ program, and the software which gets the info through pipe needs a char* script.
If I understood well, that is what is called a c-string (null-terminated sequence of characters).
I encounter the same problem while using system commands inside my program (see the example below).
It makes me struggle a lot with the difference between c_string and string: I can't easily concatenate two c_strings and I am forced to use some kind of trick like this to convert them:
Indeed, that works for this occurrence, and I was sure I had already tried it, sorry...
Though it works only for this problem, I still can't concatenate them easily.
For [other] example, to write "T = 100" in the script I send through the pipe, I use this complicated translation:
Then use const_cast. This is fine as long as your pipe thing does not write to the C strings. Which it couldn't do anyway because it contains string literals.
Oh! My bad... I get to use c_strings but I'm still not very comfortable with them...
Unfortunately it still doesn't work... I know get Error 4 error C2440: 'initializing' : cannot convert from 'char **' to 'char *[]' pipecmd.cpp 70
The 1st variable is named const_script1 and the second one script1...
I don't get the second statement you made, sorry... Here is this whole part of the code, with cstr_time and cstr_temp the variables set as said earlier in this conversation (Apr 20, 2012 at 12:37pm)
const_cast works fine, but the initialization does not. char* script1[] = ... declares an array of char*. You're trying to initialize it with a pointer to a pointer to char. That's not gonna work.
Hi again Athar, sorry for the delay in my replies and thanks for your continuing help
I mean, yes the initialization works : my whole program runs this way already (it is just that the new and deletes are a pain in the butt, and the const_cast could really help me to get rid of them), and this syntax is actually what I started with (p352 of http://www.gwb.com/pdf/GWB9/GWBreference.pdf).