Go Back   Velocity Reviews > Newsgroups > C++
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C++ - stream converting

 
Thread Tools Search this Thread
Old 10-31-2003, 04:02 PM   #1
Default stream converting


Hi there!

I have a problem concerning the file input to a c++ program: the
expected input is either in binary or in some kind of text format;
what I finally want is the binary version.
I know how to translate between these two versions and would like to
write some kind of wrapper. This wrapper should open the text file and
provide an istream which behaves exactly like the ifstream of an
equivalent binary file would. Is there a smart way to do this?
Greetings,
Moritz


Moritz Tacke
  Reply With Quote
Old 10-31-2003, 04:43 PM   #2
Mike Wahler
 
Posts: n/a
Default Re: stream converting

"Moritz Tacke" <> wrote in message
news: om...
> Hi there!
>
> I have a problem concerning the file input to a c++ program: the
> expected input is either in binary or in some kind of text format;
> what I finally want is the binary version.
> I know how to translate between these two versions and would like to
> write some kind of wrapper. This wrapper should open the text file and
> provide an istream which behaves exactly like the ifstream of an
> equivalent binary file would. Is there a smart way to do this?


No 'wrappers' or 'smartness' required:

std::ifstream input("myfile.txt", std::ios::binary);

-Mike




Mike Wahler
  Reply With Quote
Old 11-01-2003, 09:37 AM   #3
Moritz Tacke
 
Posts: n/a
Default Re: stream converting
>
> No 'wrappers' or 'smartness' required:
>
> std::ifstream input("myfile.txt", std::ios::binary);
>
> -Mike


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.

Hm. I hope I did succeed in formulating the point this time...
Greetings!
Moritz


Moritz Tacke
  Reply With Quote
Old 11-03-2003, 09:38 AM   #4
Ivan Vecerina
 
Posts: n/a
Default Re: stream converting
"Moritz Tacke" <> wrote in message
news: 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





Ivan Vecerina
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stream DVDs with full dolby digital from vob files possible? (extenders?) markm75 DVD Video 6 11-21-2007 05:09 PM
Convert DVD with subtitle stream to DivX with same subtitle stream(selectable) malise Software 2 04-17-2007 10:15 AM
Now I introduce some popular software of multimedia eightsome@gmail.com DVD Video 0 03-28-2006 02:29 PM
DVD to mpeg2 (with no change in mpeg stream and conversion of ac3 to wav)? tim koster DVD Video 0 10-06-2003 10:42 PM
HD-DVD and DVD's future Phil Riker DVD Video 68 09-28-2003 09:32 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46