How to embed commandline arguments in a execution command?

115 views Asked by At

I need to pass the commandline arguments of my C++ code as the commandline arguments of my python script.

My code looks like:

int main(int argc,char * argv[]) {
FILE *in;
char buff[512];

cout<<argv[1];

string str = "python comparescript.py "+argv[1]+" "+argv[2]+" "+argv[3];

if(!(in = popen(str, "r"))){
    cout<<"Image Comparison made successful";
}
cout<<"Image Comparison made successful";

It shows an eror like :

error: invalid operands of types 'const char [25]' and 'char*' to binary 'operator+'

How to append my commandline arguments with the python execution command?

1

There are 1 answers

2
Some programmer dude On BEST ANSWER

To be able to concatenate strings using the + operator, at least one of them needs to be a std::string object.

The simplest solution? Just do

string str = string("python comparescript.py ")+argv[1]+" "+argv[2]+" "+argv[3];