Jeff Abrahamson on 20 Nov 2003 19:39:02 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] (no subject)


Looks like party of your newbie-ism extends to differentiating between
the subject and the cc line in your mail client. ;-)

Anyway, if it works, at your level, that's not bad.

The only issue with sprintf is making sure you don't overrun buffers.
But taking the log and checking allocation length is also fine.

-Jeff


On Wed, Nov 19, 2003 at 09:30:19AM -0500, Mike Chirico wrote:
>   [46 lines, 134 words, 1105 characters]  Top characters: _tinerao
> 
> Sorry about the newbie question. What's the best way 
> to convert numbers to strings in C++. The following works,
> but is it better than using the sprintf() "old C" way of 
> converting?
> 
> 
> #include <iostream>
> #include <string>
> #include <sstream>
> #include <list>
> 
> using namespace std;
> int main(void)
> {
>   list<string> ml;
>   string s;
>   stringstream ss;
> 
> 
> 
>   for(int i=0; i < 3000; ++i)
>     {
>        ss << "sample text " << i ;
>        ml.push_front( ss.str() );
>        ss.str("");
>     }
> 
>   cout << ml.front() << endl;
> }
> 
> 
> What about the fact that the stringstream has to be cleared
> ss.str("")...does that incur additional overhead? Maybe 
> there is a better way?
> 
> Anyway..still reading through "The C++ Programming Lang", 
> Stroustrup and The C++ Standard Lib, Josuttis for an answer.
> 
> Regards,
> 
> 
> Mike Chirico
> ___________________________________________________________________________
> Philadelphia Linux Users Group         --        http://www.phillylinux.org
> Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
> General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B

Attachment: pgpmyMn66GuQY.pgp
Description: PGP signature