"Moritz Tacke" <ta**@informatik.uni-freiburg.de> wrote in message
news:23**************************@posting.google.c om...
....
| > std::ifstream input("myfile.txt", std::ios::binary);
....
| Well, it looks like I didn't express myself correctly: the binary
| format and the "text"-format are qualitatively different. The text
| format is some kind of encoding of the binary one, where four bytes of
| "text" are used to encode three bytes of the "binary".
| What I am trying to do right now is to write some kind of wrapper
| which reads the four "text"-bytes and converts them to the three
| corresponding binary-bytes; this wrapper should be used by the other
| parts of the program as if it was an ifstream which directly reads the
| binary file.
Hi Moritz,
The way to do what you are looking for is to implement a custom
streambuf class (the polymorphic buffering class which handles
the i/o behind any standard stream). Your implementation
of this file would generate the buffer by translating data
read from another stream.
For some examples, you may check Dietmar Kühl's website:
http://www.informatik.uni-konstanz.de/~kuehl/
Dietmar authored part of Josuttis' (excellent) book
"The C++ Standard Library - A Tutorial and Reference" (in particular
sections related to the i/o stream library), a valuable reference.
But I think that you would be picking the wrong level of
abstraction by working at the level of the streams.
It would probably be better to define a higher-level
interface (abstract base class) to read the contents
of a file, and implement it for both the ascii and binary
file formats.
Then, if needed, you can do the same to write both
formats, and -- if needed -- perform a translation
on-the-fly.
Regards,
Ivan
--
http://ivan.vecerina.com
Brainbench MVP for C++ <>
http://www.brainbench.com