Topic: is num_put facet of standard C++ insufficient or incomplete?


Author: vishalkochhar@yahoo.com (Vishal)
Date: Fri, 2 May 2003 21:30:20 +0000 (UTC)
Raw View
Dietmar Kuehl wrote:

> Vishal wrote:
> > The num_put facet does not provide functions to write char, short or
> > integer (or their unsigned counterparts). All these are written in terms
> > of long or unsigned long. That has serious limitations if one has to use
> > streams for other purposes.
>
> Can be more specific about these "other purposes"? My guess is that you
> want to use this stuff for some form of binary representation. In this
> case, using 'num_put' or the standard IOStreams (ie. the hierarchy
> deriving from 'basic_ios') is probably not a reasonable approach: these
> classes are for text formatted I/O. These classes are not at all suited
> for binary I/O.
>
> You might want to use a class similar to 'num_put' for binary formatting
> together with a hierarchy of stream classes which are modelled along
> the lines of the IOStreams class. Internally, you would probably still
> use stream buffers, however, to read or write the bytes.

Thanks. You are right. Let's say for binary representation. I already  have a
different class for this but I was wondering why we could not use num_put
instead. On second thoughts, it probably is okay like this ( I see the light
now :-)).

I agree that IOStreams is definitely not the reasonable approach for this task
(Another reason being that it does not propagate exceptions).

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: vishalkochhar@yahoo.com (Vishal)
Date: Thu, 1 May 2003 23:09:36 +0000 (UTC)
Raw View
The num_put facet does not provide functions to write char, short or
integer (or their unsigned counterparts). All these are written in terms
of long or unsigned long. That has serious limitations if one has to use
streams for other purposes.

Can this be changed by the standard to include char, short etc as well?
It would be nice if there functions that had int8_t, int32_t etc as
parameters.

Vishal

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: dietmar_kuehl@yahoo.com (Dietmar Kuehl)
Date: Fri, 2 May 2003 15:18:52 +0000 (UTC)
Raw View
Vishal wrote:
> The num_put facet does not provide functions to write char, short or
> integer (or their unsigned counterparts). All these are written in terms
> of long or unsigned long. That has serious limitations if one has to use
> streams for other purposes.

Can be more specific about these "other purposes"? My guess is that you
want to use this stuff for some form of binary representation. In this
case, using 'num_put' or the standard IOStreams (ie. the hierarchy
deriving from 'basic_ios') is probably not a reasonable approach: these
classes are for text formatted I/O. These classes are not at all suited
for binary I/O.

You might want to use a class similar to 'num_put' for binary formatting
together with a hierarchy of stream classes which are modelled along
the lines of the IOStreams class. Internally, you would probably still
use stream buffers, however, to read or write the bytes.
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]