*/
File copy function in C++
Submitted By:
WEBMASTER
Rating:





(
Rate It)
NOTE: Some downloads must be obtained through publishers´s site.
Do you want to get your software listed on this site? Go to our
submissions area.
Screenshot
Details
Number of downloads:
17581
Comments (9)
good




Posted by: a on Sunday, February 10, 2002
good :]
SuSE 9.1




Posted on Monday, September 20, 2004
Works just like expected! Great piece of work. Keep the software comming.
=]
Not useful for binary files under Windows




Posted on Thursday, January 20, 2005
I wanted to use this to copy .jpg files but they end up being corrupted. I think this source code is really only good for plain text files.
this version works in Windows, also .jpg files






























































































































































































































































Posted by: linhmt on Thursday, August 04, 2005
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int n, char* args[]) {
if (n < 3) {
cout << " Syntax: copyfile <src_file> <dest_file>";
return 0;
}
string src = args[1], dest = args[2];
ifstream fin(src.c_str(), ios::in | ios::binary);
ofstream fout(dest.c_str(), ios::in); // open with this mode to check whether file exists
if (fin.fail()) {
// reset status flags
fin.clear();
cout << " source file does not exist, try it again";
return 0;
}
if (!fout.fail()) {
fout.close();
cout << " destination file already exists, try it again";
return 0;
}
else {
fout.close();
fout.open(dest.c_str(), ios::out | ios::binary); // change to writting mode
}
int BUFFER_SIZE = 128;
char buffer[BUFFER_SIZE];
while (!fin.eof() ) {
fin.read( buffer, BUFFER_SIZE);
if (fin.bad()) {
cout << "Error reading data" << endl;
exit( 0 );
}
else
fout.write(buffer, fin.gcount());
};
fin.close();
fout.close();
return 0;
}
use this code






























































































































































































































































Posted on Thursday, October 06, 2005
bSuccess=CopyFilesrcFileName, desFileName,FALSE);
Isn't easier this?






























































































































































































































































Posted by: Danyx++ on Friday, December 23, 2005
#include <fstream>
using std::ifstream;
using std::ofstream;
using std::ios;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream ifs("C:\\Photo.jpg",ios::in|ios::binary);
ofstream ofs("C:\\PhotoCopy.jpg",ios::out | ios::binary);
ofs << ifs.rdbuf();
return 0;
}
thanks, but doesn't work :(






























































































































































































































































Posted by: John on Saturday, January 21, 2006
Thanks for the amendment code above. When I run it, it makes the new file but with zero bytes after the copy.