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

reverse a file's content

P: n/a
ray
I want to reverse a large file's content to a new file by bytes. For
example, If a file's content is 0A0B0C0D, I expected the result file's
content is 0D0C0B0A. Is there is elegent and efficient way?
I have read the STL but could not find a satisfactory way. Any
suggestions? TIA.

Apr 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ray wrote:
I want to reverse a large file's content to a new file by bytes. For
example, If a file's content is 0A0B0C0D, I expected the result file's
content is 0D0C0B0A. Is there is elegent and efficient way?
I have read the STL but could not find a satisfactory way. Any
suggestions? TIA.


How about using boost's mapped_file class to memory map the file, then
using the std::reverse algorithm? It would be elegant and efficient, if
not exactly standard.

Apr 13 '06 #2

P: n/a
ray wrote:
I want to reverse a large file's content to a new file by bytes. For
example, If a file's content is 0A0B0C0D, I expected the result file's
content is 0D0C0B0A. Is there is elegent and efficient way?
I have read the STL but could not find a satisfactory way. Any
suggestions? TIA.


I think the most efficient way would be to do it blockwise. Seek to some
kilobytes before the end of the input file and read to the end in one
block. Reverse it in memory and write the result to the target file. Now
seek back in the input file and do the same with the next (or rather
previous) block and so on.

Apr 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.