【发布时间】:2018-04-05 14:23:21
【问题描述】:
我一直在搜索,但似乎无法正确地将 CopyFile 命令中的路径替换为存储路径的变量。
这个想法是复制一个文件并用不同的数字重命名到某个目录。我设法让代码使用固定的路径名和文件名。但我需要复制这 1000 次,每次使用不同的数字。希望有人能告诉我如何将变量合并到 copyfile 命令中。
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string>
#include <sstream>
using namespace std;
int main()
{
int a=6;
string name = "Slide";
string newname;
string directory = "d:/--- STEPHANE FILES ---/powerpoint/";
string destination;
ostringstream oss;
oss << name << a ;
newname = oss.str();
ostringstream oss1;
oss1 << directory << newname << ".JPG";
destination = oss1.str();
cout << destination;
CopyFile("d:/--- STEPHANE FILES ---/powerpoint/Slide1.jpg", destination, TRUE);
return 0;
}
【问题讨论】:
标签: c++ file-copying pathname