How to send a string to system()

i am just starting out and i wrote a simple program to ask basic questions and than assemble them into a fully formed command line operation. i cant figure out how to pass the finished string to system() on my test program

at the end of the program directly before return 0 i have a line

system("echo finalstring");

the issue i have is the cout prints the contents of finalstring however the echo through system simply prints finalstring

note the final version will actually put the command directly into the command processor i am just using echo as a safety so i can see the logic is working.

if the system() command cant be used in this manner than i would like to know how to properly send the string to the commandline.
Last edited on
First check the documentation.
system takes a const char*.

Now check the documentation of string for helpful functions.
Here's a function that returns a const char* from a string object.

So now you know how to get a const char* from finalstring:

So get that and pass it to system.

Also, using system is bad bad bad. You shouldn't. You should look up the proper way to start a new process on your operating system.
Last edited on
Topic archived. No new replies allowed.