0

Hello,
I'm learning C++ and i want to build a simple program that copy files, remember that i want a program that copy all types of files, not only *.txt or only binary files.

Thanks,
Nathan Paulino Campos

3
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by Nathan Campos
0

First, open the file for reading in binary mode.
Second, open the output file for writing in binary mode
declare an unsigned char array of size 255

create a while loop and continue while reading

while( infile.read( buf, sizeof(buf) )
{
    size_t len = infile.gcount(); // get the number of bytes read
    outfile.write( buf, len );
}
0

I was looking for some reference and here is a working code:

ofstream(argv[2]) << ifstream(argv[1]).rdbuf();

Thanks!

0

If you are using MS-Windows you can call win32 api functions FindFirstFile() and FindNextFile() to get a list of all the files. Then for each of the filenames it returns just select the ones you want to copy. See this example.

0

Thanks for the help!
+1 Of Reputation, because you help me outside of the question, for my future project.

Thanks!

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.