copying file using fstream
I know that this code is available on reference programs on this site, I am posting this program to know meaning from line 10 to 18.
what is inbuf,outbuf,sbumpc ??
can anybody explain this a little more ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
// copy a file using file stream buffers
#include <fstream> // std::filebuf, std::fstream
#include <cstdio> // EOF
int main () {
std::fstream src,dest;
src.open ("test.txt");
dest.open ("copy.txt");
std::filebuf* inbuf = src.rdbuf();
std::filebuf* outbuf = dest.rdbuf();
char c = inbuf->sbumpc();
while (c != EOF)
{
outbuf->sputc (c);
c = inbuf->sbumpc();
}
dest.close();
src.close();
return 0;
}
|
Topic archived. No new replies allowed.