0

Basically I'm trying to copy a file from one place to another but I want the user to be able to change were to because its for a steam game and everyone has a diffident username.

system("copy GameMenu.res C:\\Program Files (x86)\\Steam\\steamapps\\"login"\\counter-strike source\\cstrike\\resource\\GameMenu.res");

In this line where it says "login" I want for people to be able to type their username and so it is still a part of the directory or whatever the thing is called. Please help me.

here is the code here is the whole code so you can see what's wrong with it:

#include <iostream>
#include <cmath>
#include <string>
int main ()
{
using namespace std;

string login;
int drive;

cout << "What is your steam login??" << endl;

cin >> login;

system("timeout 2");

system("cls");

cout << "Your files are being copied " << login << "." << endl;

system("copy GameMenu.res C:\\Program Files (x86)\\Steam\\steamapps\\"login"\\counter-strike source\\cstrike\\resource\\GameMenu.res");

system("pause");

system("cls");

system("timeout 1");

return 0;

}
2
  • You also need to look at enclosing the copy destination in ", since it has spaces.
    – crashmstr
    Commented Apr 2, 2012 at 14:32
  • Plus, you make assumption on where they have steam installed.
    – crashmstr
    Commented Apr 2, 2012 at 15:02

1 Answer 1

2

You could prepare your String using concatenation for your login name problem and then convert it to const char *:

string str = "copy GameMenu.res \"C:\\Program Files (x86)\\Steam\\steamapps\\" + login + "\\counter-strike source\\cstrike\\resource\\GameMenu.res\"";
const char * c = str.c_str();

system(c);

Also as crashmstr mentioned in the comments, as you have spaces in your path you could have problems, so consider following his advice.

12
  • I tried that but its not compiling and i get this error C:\Users\Seb\Documents\template.cpp cannot convert std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to const char*' for argument 1' to int system(const char*)'
    – user1308252
    Commented Apr 2, 2012 at 14:35
  • @user1308252 and if you prepare your const char * before like my updated answer?
    – talnicolas
    Commented Apr 2, 2012 at 14:37
  • So now how would I put this into the whole code i know literately minimum about c++ as I started learning yesturday so is it a lot of work to do it?
    – user1308252
    Commented Apr 2, 2012 at 14:42
  • @user1308252 well just replace system("copy GameMenu.res C:\\Program Files (x86)\\Steam\\steamapps\\"login"\\counter-strike source\\cstrike\\resource\\GameMenu.res"); by the three lines I gave you.
    – talnicolas
    Commented Apr 2, 2012 at 14:46
  • and i tryed to vote up but it says i need 15 reputation but im only on 1
    – user1308252
    Commented Apr 2, 2012 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.