By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

file io question

P: n/a
I'm looking for a way to copy a segment of a binary file.
ie. from start position (>=0) to end position (<= eof).
Any suggestions? (preferably stl)
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Fluke" <fl***@something.com> wrote in message
news:IQ********************@twister01.bloor.is.net .cable.rogers.com...
I'm looking for a way to copy a segment of a binary file.
ie. from start position (>=0) to end position (<= eof).
Any suggestions? (preferably stl)


void copy_segment(istream& input, streampos start, streampos end,
vector<char>& output)
{
input.seekg(start);
output.resize(end - start);
input.read(&output[0], end - start);
}

Untested code, and obviously could do with the addition of some error
checking.

john
Jul 22 '05 #2

P: n/a

"John Harrison" <jo*************@hotmail.com> wrote in message
news:2h************@uni-berlin.de...

"Fluke" <fl***@something.com> wrote in message
news:IQ********************@twister01.bloor.is.net .cable.rogers.com...
I'm looking for a way to copy a segment of a binary file.
ie. from start position (>=0) to end position (<= eof).
Any suggestions? (preferably stl)


void copy_segment(istream& input, streampos start, streampos end,
vector<char>& output)
{
input.seekg(start);
output.resize(end - start);
input.read(&output[0], end - start);
}

Untested code, and obviously could do with the addition of some error
checking.

john


bool copy_segment(istream& input, streampos start, streampos end,
vector<char>& output)
{
vector<char> temp(end - start);
if (!input.seekg(start) || !input.read(&temp[0], end - start))
return false;
output.swap(temp);
return true;
}

Still untested.

john
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.