bg
2006-04-26 13:35:10 UTC
hi all,
what the best (stl) way of copy input to output using ofstreams/ifstreams
I currently have something like this
ofstream output(output_file_name.c_str(), ios_base::out | ios_base::trunc |
ios_base::binary);
// ... for each file ...
ifstream input(inputname.c_str(),ios_base::in|ios_base::binary);
do
{
// copy chunks of the input to the output
// until theres nothing more to read
input.read(buf, buffsize);
tot = input.gcount();
if(tot>0) output.write(buf,tot);
} while(tot>0);
input.close();
This strikes me as rather clunky and inelegant, there must be a better way,
std::copy? istream iteration ?
Any thoughts appreciated.
TIA
bg
what the best (stl) way of copy input to output using ofstreams/ifstreams
I currently have something like this
ofstream output(output_file_name.c_str(), ios_base::out | ios_base::trunc |
ios_base::binary);
// ... for each file ...
ifstream input(inputname.c_str(),ios_base::in|ios_base::binary);
do
{
// copy chunks of the input to the output
// until theres nothing more to read
input.read(buf, buffsize);
tot = input.gcount();
if(tot>0) output.write(buf,tot);
} while(tot>0);
input.close();
This strikes me as rather clunky and inelegant, there must be a better way,
std::copy? istream iteration ?
Any thoughts appreciated.
TIA
bg