Question

I have 2 integers, whom I converted to const char* by passing to a user defined function. Now I want to append these 2 variables into a command line string as

    "gnome-terminal -x sh -c 'cd; cd project/into_bot/; sh ./matlab_batcher.sh localize \""+num1+","+num2+"\"; exec bash;

I know its very basic, but am bad with data types. how do I append these 2 const char here? This method is not working as it throws error, saying binary operator for const char*. Please help me though its rudimentary.

num1 and num2 are the variables

Était-ce utile?

La solution

If num1 and num2 are const char *, you can use std::string.

std::string cmd_line = std::string() +
    "gnome-terminal -x sh -c 'cd; cd project/into_bot/; "
    "sh ./matlab_batcher.sh localize \"" +num1+","+num2+"\"; "
    "exec bash;";

system( cmd_line.c_str() );

Semantically what's happening here is you create a temporary variable with std::string() which is used to build the string, then after everything is built it's used to initialize the permanent variable cmd_line.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top