<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2722.2800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<BLOCKQUOTE 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">-----Ursprüngliche Nachricht----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>Von:</B> 
  <A href="mailto:marwie@gmx.net" title=marwie@gmx.net>Martin Wiebusch</A> 
</DIV>
  <DIV style="FONT: 10pt arial"><B>An:</B> <A 
  href="mailto:kdevelop@barney.cs.uni-potsdam.de" 
  title=kdevelop@barney.cs.uni-potsdam.de>kdevelop@barney.cs.uni-potsdam.de</A> 
  </DIV>
  <DIV style="FONT: 10pt arial"><B>Gesendet:</B> Samstag, 12. Februar 2000 
  13:49</DIV>
  <DIV style="FONT: 10pt arial"><B>Betreff:</B> Re: int to string 
  conversion</DIV>
  <DIV><BR></DIV>
  <DIV>Jerry L Kreps wrote:<BR>> <BR>> Martin Wiebusch wrote:<BR>> 
  ><BR>> > Hi,<BR>> > i was just wondering whether there is a 
  function to convert integer<BR>> > values to strings in any of the 
  libaries. I already tried itoa, Itoa and<BR>> > IntToStr. I also noticed 
  there ist an Itoa function defined in the<BR>> > Integer.h header. But I 
  don't really need an Integer class, just a<BR>> > little function to 
  convert usual int variables into strings.<BR>> <BR>> You can use I/O 
  manipulators (page 259, Practical C++<BR>> programming)<BR><BR>Thankx, but 
  I knew that Numbers are converted to strings when you write<BR>them on stdout 
  with cout << ...<BR>What I want to do is writing that what in your 
  examples appears on the<BR>screen to a variable of the type "string".<BR>Tilo 
  Riemer just wrote me, that I can use "sprintf". But then I have to<BR>guess 
  how many digits number will have. So it would be great if 
there</DIV></BLOCKQUOTE>
<DIV><FONT size=2>Don't you think it is so difficult to estimate some upper 
limit of characters needed?</FONT></DIV>
<DIV><FONT size=2>For a 32-Bit int you need 9+1+1 chars (9 digits + sign + 
terminating NUL), for a 64 Bit int there would be some other figure but in any 
case the overhead for the conversion would be drastically less than using 
something dynamic.</FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV>was something like "sprintf" for instances of the string class. 
  Any<BR>idea?</DIV></BLOCKQUOTE>
<DIV>how about:<BR></DIV>
<DIV>std::string itoa (int i)<BR>{<BR>    char tmp [<the 
constant calculated above>];<BR> <BR>    sprintf (tmp, 
"%d", i);<BR>    return (std::string (tmp));<BR>}<BR><FONT 
size=2><FONT size=2></FONT></FONT></DIV>
<DIV><FONT size=2><FONT size=2>Gottfried Ganßauge</FONT></FONT></DIV>
<DIV><FONT size=2><FONT size=2><BR>M.P.W.LASEC Software GmbH<BR>Potsdamer Straße 
99<BR>10785 Berlin<BR><A 
href="http://www.mpwsoftware.de">http://www.mpwsoftware.de</A><BR><A 
href="mailto:ganssauge@mpwsoftware.de">ganssauge@mpwsoftware.de</A></DIV></FONT></FONT></BODY></HTML>