Support Forums

Full Version: [C++] Combining Strings?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to know how to put multiple previously declared strings together to form a system command in a console application. I can get a SINGLE "string" to work, but how can I have 3 put together, declared by input?

Also needs to work with other text that ISN'T declared by input.

This is what I have so far, don't bother commenting on it, I'm a complete noob to this.
Code:
char myArray[75];
    char myArray2[75];
    char myArray3[75];
    cout << "Please enter the directory of the first file to bind: ";
    cin.getline( myArray, 75, '\n');
    cout << "Please enter the directory of the second file to bind: ";
    cin.getline( myArray2, 75, '\n');
    cout << "Please enter the directory of the output file: ";
    cin.getline( myArray3, 75, '\n');
    system("copy /b", myArray, " + ", myArray2, myArray3);
    system("PAUSE");
    return EXIT_SUCCESS;
I would do this:

Code:
string command;
command += "copy /b ";
command += myArray;
command += " + ";
command += myArray2;
command += " ";
command += myArray3;
system(command.c_str());