xcopy in system()

I need to use xcopy here (since I don't know a better way). My question is, how do I need to format the line with system() so that the compiler can read it. I'm using GNU GCC with CodeBlocks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{

// Need to identify two strings that will be used to take user input to pull
// the correct files from the computer

string driveLetter;
string userName;

cout << "What is the drive letter of your external?" << endl;
cin >> driveLetter;
cout << "What is the user ID of the profile you want to copy?" << endl;
cin >> userName;

//The neccessary variables have been set and now copying can begin

system("xcopy" C:\Documents and Settings\%userName%\My Documents %DriveLetter%:\USERS\%userName%\Documents)
¿why don't simply use batch?

man wrote:
int system(const char *command)
system() executes a command specified in command
1
2
3
4
5
6
7
8
9
10
std::string 
//note the forward slashes, (or escape the backwards \\)
   source = std::string("C:/Documents and Settings/") + userName + std::string("/My Documents"),
   destiny = driveLetter + std::string(":/USERS/")+userName+std::string("/Documents");
//also, you should quote your arguments
source = std::string("\"") + source + std::string("\"");
destiny = std::string("\"") + destiny + std::string("\"");

std::string command = std::string("xcopy") + std::string(" ") + source + std::string(" ") + destiny;
system( command.c_str() );
Originally this whole this came from a batch file. I just wanted to try to implement it into c++ just to have one more thing to learn, though I found myself rather stuck.
Topic archived. No new replies allowed.