number/string conversions in c++ (was: Re: [lug] C++ libraries in Linux)

Tkil tkil at scrye.com
Tue Sep 18 00:01:39 MDT 2001


>>>>> "Keith" == Keith C Herold <herold at cslr.Colorado.EDU> writes:

Keith> Can it be true?  There are no converters to go from an int to a
Keith> string?  Or a double to a string?

in c++?  use strstreams.  (or stringstreams; they changed their names
at some point during the last 10 years or so.)  basically, they act
like iostreams, but you can suck the contents of their buffers out
after the fact.  so, you do formatted output to a memory area, which
is effectively the same thing as converting from a number to a string.

of course, sprintf is still available, but it's fraught with
annoyances (buffer length, type-checking of operands, etc).  but it's
still there.

t.



More information about the LUG mailing list