I'm trying to move files on linux by using C++. The Problem is, that the source file and the destination folder can be in different partitions. So I can't simply move the files. Ok. I decided to copy the file and delete the old one.
//-----
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;
}
//-----
Now my problem. I realized, this method is very slow. It takes 47 seconds for 100MB. Simply copy a file with the console command takes 2-3 seconds.
Does anybody have an idea?