Topic: is cout.form conforms to standard C++
Author: "Joe" <swimmar@hotmail.com>
Date: Tue, 13 Feb 2001 02:11:33 GMT Raw View
Can someone point me to a page that has the various inconsistencies with the
ANSI standard that VC++ has?
Thanks,
Joe
"Balog Pal" <pasa@lib.hu> wrote in message
news:3a73f964@andromeda.datanet.hu...
> "Rene Stolle" <stolle@informatik.uni-jena.de> wrote
>
> > int main ()
> > {
> > int a = 1;
> > double b = 3.123;
> > cout.form ("total = %d, correct = %f \n", a, b) << endl;
> > }
> > Belongs cout.form to the C++ standard or not?
>
> No, and I doubt the comitee would ever consider to make something like
that
> standard.
>
> However, I would find a manipulator or stream function taking a
> printf-compatible format string pretty useful. ie:
>
> cout << format("%04X") << 1;
>
> The action of format would be equivalent to a series of manipulators,
> issuing hex, precision, width, fill, whatever, that will result output
> identical to printf on the next <<. The type part (d, f, s, etc) would be
> ignored after the format got deciphered. (Alternatively it could be
> remembered, and if a non-compatible type passed as the next operation, the
> stream falls into bad state.)
>
> Anyone found people using sprintf or something alike just 'soc stream
usage
> grows way cumbersome fhen formatting comes around?
>
> Paul
>
> Paul
>
>
> ---
> [ 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.research.att.com/~austern/csc/faq.html ]
> [ Note that the FAQ URL has changed! Please update your bookmarks. ]
>
>
---
[ 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.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: "Balog Pal" <pasa@lib.hu>
Date: Mon, 29 Jan 2001 06:23:51 GMT Raw View
"Rene Stolle" <stolle@informatik.uni-jena.de> wrote
> int main ()
> {
> int a = 1;
> double b = 3.123;
> cout.form ("total = %d, correct = %f \n", a, b) << endl;
> }
> Belongs cout.form to the C++ standard or not?
No, and I doubt the comitee would ever consider to make something like that
standard.
However, I would find a manipulator or stream function taking a
printf-compatible format string pretty useful. ie:
cout << format("%04X") << 1;
The action of format would be equivalent to a series of manipulators,
issuing hex, precision, width, fill, whatever, that will result output
identical to printf on the next <<. The type part (d, f, s, etc) would be
ignored after the format got deciphered. (Alternatively it could be
remembered, and if a non-compatible type passed as the next operation, the
stream falls into bad state.)
Anyone found people using sprintf or something alike just 'soc stream usage
grows way cumbersome fhen formatting comes around?
Paul
Paul
---
[ 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.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: James.Kanze@dresdner-bank.com
Date: Mon, 29 Jan 2001 08:51:08 GMT Raw View
In article <3a73f964@andromeda.datanet.hu>,
"Balog Pal" <pasa@lib.hu> wrote:
> "Rene Stolle" <stolle@informatik.uni-jena.de> wrote
> > int main ()
> > {
> > int a = 1;
> > double b = 3.123;
> > cout.form ("total = %d, correct = %f \n", a, b) << endl;
> > }
> > Belongs cout.form to the C++ standard or not?
> No, and I doubt the comitee would ever consider to make something
> like that standard.
I hope not, at any rate.
> However, I would find a manipulator or stream function taking a
> printf-compatible format string pretty useful. ie:
> cout << format("%04X") << 1;
> The action of format would be equivalent to a series of
> manipulators, issuing hex, precision, width, fill, whatever, that
> will result output identical to printf on the next <<. The type part
> (d, f, s, etc) would be ignored after the format got
> deciphered. (Alternatively it could be remembered, and if a
> non-compatible type passed as the next operation, the stream falls
> into bad state.)
It's pretty simple to implement for the basics, and impossible if you
insist on supporting all of the printf options. In practice, I've
found that most formatting falls into a few simple categories, so I've
implemented manipulators for those:
cout << ffmt( width , prec ) << aDouble ;
The ffmt manipulator sets the float field to fixed, plus the width and
precision as specified. A hexfmt manipulator sets hex, and also sets
the fill character to 0. Etc.
The manipulators are designed to restore the initial state at the end
of the full expression. There's nothing worse than having someone
insert a single output in hex, and seeing all of the following output
also appear in hex.
--
James Kanze mailto:kanze@gabi-soft.de
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
Ziegelh ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627
Sent via Deja.com
http://www.deja.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.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Rene Stolle <stolle@informatik.uni-jena.de>
Date: Tue, 9 Jan 2001 18:34:45 GMT Raw View
gcc allows to print stuff similar to the C format string,
e.g.:
#include <iostream>
using namespace std;
int main ()
{
int a = 1;
double b = 3.123;
cout.form ("total = %d, correct = %f \n", a, b) << endl;
}
will be compiled by c++ -ansi -Wall stream.cpp with no warning
(gcc 2.95.2). I can't compile it with borland or MS C++ and I
don't find it in any standard book. But I didn't find any advise
that this is a non standard feature of gcc.
Belongs cout.form to the C++ standard or not?
best regards,
Rene Stolle
Jena University, Faculty of Mathematics and Computer Science
Ernst-Abbe-Platz 1-4, Room#3205, D-07743 Jena, Germany
Tel: (+49) 3641 9 46331 or any time: (+49) 177 2316698
Fax: (+49) 3641 9 46302 eMail: stolle@informatik.uni-jena.de
Linux/UNIX Software database: http://www.stolles.net/lusdb
---
[ 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.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: kuehl@ramsen.informatik.uni-konstanz.de (Dietmar Kuehl)
Date: Tue, 9 Jan 2001 21:46:58 GMT Raw View
Hi,
Rene Stolle (stolle@informatik.uni-jena.de) wrote:
: Belongs cout.form to the C++ standard or not?
No, it does not belong to the C++ standard.
--
<mailto:dietmar_kuehl@yahoo.de> <http://www.dietmar-kuehl.de/~kuehl/>
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.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]