First off, let it be known that I'm relatively new to programming and VERY new to C/C++. Now that that's over...
I have a problem with a simple command line program that is meant to collect a few user inputs and then put them into a shell command with flags. The program then puts those values together to form a command like: program.exe -a value -b value -c value.
The problem is that I can't find a way to use strings in a system() line(the compiler asks for a const char because it can't use a string for System()). I've searched the forum for a while and haven't seen anything to help me(though it seems that the soulution is always right in front of my eyes whenever I ask for help), so sorry if this has already been answered somewhere else.
Here is what I've got so far:
In the end, I want to be able to incorporate this into a larger application that will serve as a "frontend" for people new to terminal-based applications(or just lazy people like myself).Code:#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { char inone[21]; char intwo[21]; char inthree[21]; char app[21]; string space( " " ); cout<< "What is the name of the executable?: "; cin.getline ( app, 21 ); //name of file to run, assuming it's in 'system32' cout<< "What is flag one?: "; cin.getline ( inone, 21 ); //flag, along with a value. eg: "-b 1024" cout<< "What is flag two?: "; cin.getline ( intwo, 21 ); cout<< "What is flag three?: "; cin.getline ( inthree, 21 ); cout<< "Your command will be: " << ( app ) << ( space ) << ( inone ) << ( space ) << ( intwo ) << ( space ) << ( inthree ) << "... Continue?"; cin.get(); /*here is where I want to put a system() line or something similar. the problem is that I can't figure out how to combine the flags and app name into a string and put it into that system() line.*/ }



LinkBack URL
About LinkBacks



If anyone's interested, this is what I was integrating it into: