Re: Converting int to string
From: r norman (rsn__at__comcast.net)
Date: 08/05/04
- Previous message: Frank Yeh: "Re: Converting int to string"
- In reply to: Frank Yeh: "Re: Converting int to string"
- Next in thread: tom_usenet: "Re: Converting int to string"
- Reply: tom_usenet: "Re: Converting int to string"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 05 Aug 2004 07:34:32 -0400
On 5 Aug 2004 01:17:26 -0700, pwipwi@ms66.hinet.net (Frank Yeh) wrote:
>r norman <rsn_@_comcast.net> wrote in message news:<gea0h0tvgt500s46ihut2b8egk5h97mm7k@4ax.com>...
>> On Tue, 3 Aug 2004 19:18:25 -0400, "David Mohandas"
>> <david_mohandas@yahoo.com> wrote:
>>
>> >Is there a way in STL to convert integer data type to string object or do i
>> >have to do itoa() to do that.
>> >
>>
>> As an old C programmer, I find itoa (or even sprintf!) most
>> convenient. However, here goes:
>>
>> std::ostringstream oss;
>> int i = 123;
>> oss << i;
>> std::string s = oss.str();
>
> Although the standard method is highly portable, I still find that
>using itoa is much faster. (even sprintf is faster than stringstream
>convertion). So, If you love good performace, itoa will be a better
>choice.
I tend to agree with you. However, the fact is that I have also
created innumerable bugs by using sprintf format values with the wrong
type of value. The function itoa() is not standard C or C++ and you
have to remember about _itoa or _ultoa or all the other versions. And
also "modern" programming tends to use all sorts of data items beyond
char, int, or float.
If you love good programming techniques, you will use the standard
methods. If you love good performance, then diligent attention to
your program design will yield far more effective results than relying
on a few little tricks.
- Previous message: Frank Yeh: "Re: Converting int to string"
- In reply to: Frank Yeh: "Re: Converting int to string"
- Next in thread: tom_usenet: "Re: Converting int to string"
- Reply: tom_usenet: "Re: Converting int to string"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|