-4

I opened two files and I want to find the most efficient way to put data from out file to in fill. I tried rdbuf() but it doesn't work and the outfile is the same so I need to have more explanation for rdbuf() and is there another method to append a file to another?

ofstream writeto;
writeto.open(srr.c_str(),ios::app);
cout<<"give me the file you want to copy from  : ";
string written;
cin>>written;
ifstream writefrom;
writefrom.open(written.c_str());
bcr
  • 920
  • 7
  • 28

2 Answers2

2

Assuming you want to copy the entire input file:

writeto << writefrom.rdbuf();

Also, you should use std::getline() instead of operator>> so you can account for file path/names that have space characters in them:

getline(cin, written);
Remy Lebeau
  • 505,946
  • 29
  • 409
  • 696
-2

Read a file into a stream object, read the next file into the stream. Write out the stream.

Mike
  • 172
  • 7