I have a variable in argv[1] which I need to call inside another c++ file in such a way:
system("./assemblerL.out", argv[1]);
this above is incorrect syntax as I am getting "too many arguments" errors.
What is the correct way of doing this?
system
can take only one parameter, and that´s a whole line like entered in the shell
(well, not with everything a shell like Bash got, but that doesn´t matter here).
With C++, just use std::string
to concat the parts:
system((std::string("./assemblerL.out ") + argv[1]).c_str());
Or, more readable:
std::string line = "./assemblerL.out ";
line += argv[1];
system(line.c_str());
Remember to make sure that argv[1]
exists before using it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With