Re: [C++] ostrstream vs. sprintf

From: George Greer (greerga@circlemud.org)
Date: 02/06/02


On Wed, 6 Feb 2002, Henrik Stuart wrote:

>>> one disadvantage that I noticed was cases where you want to set the
>>> size of the parameter (i.e. %20s).
>
>   As far as I recall I have seen the %20s a few places in the code,
>   might just be misrememberance. :o)

$ egrep '%[0-9.]+' *.c | wc -l
     62

I remember the first time I ever saw 'cout' after sprintf. I was (and still
am) very unimpressed. My biggest gripe with *printf() is when you have a
typedef that varies what it is in your format string.  The whole 'need a
big enough buffer' thing isn't so great but you can use snprintf() to work
around that because it tells you how much space it needs (unless you're
using GNU C library 2.0, ick).

--
George Greer
greerga@circlemud.org

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT