简体   繁体   English

使用可变目录在c ++中复制文件

[英]copying a file in c++ with variable directories

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;

}

You could prepare your String using concatenation for your login name problem and then convert it to const char * : 您可以使用串联为您的登录名问题准备String,然后将其转换为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. 同样如评论中提到的crashmstr,因为你的路径中有空格可能会有问题,所以请考虑遵循他的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM