【发布时间】:2013-11-03 02:39:01
【问题描述】:
我正在尝试使用 C++ 在 linux 上移动文件。 问题是,源文件和目标文件夹可以位于不同的分区中。所以我不能简单地移动文件。 好的。我决定复制文件并删除旧文件。
//-----
bool copyFile(string source, string destination)
{
bool retval = false;
ifstream srcF (source.c_str(), fstream::binary);
ofstream destF (destination.c_str(), fstream::trunc|fstream::binary);
if(srcF.is_open() && destF.is_open()){
destF << srcF.rdbuf(); //copy files binary stream
retval = true;
}
srcF.close();
destF.close();
return retval;
}
//-----
现在我的问题。 我意识到,这种方法很慢。 100MB 需要 47 秒。 只需使用控制台命令复制文件需要 2-3 秒。
有人有想法吗?
【问题讨论】:
-
以下答案是您最好的选择:stackoverflow.com/questions/10195343/…
标签: c++ linux file-io filesystems partition