Re: [OFF] Convert int to ustring
- From: Vinzenz 'evilissimo' Feenstra <mailinglist evilissimo-softdev de>
- To: Nickolai Dobrynin <dobrynin cs uwm edu>, gtkmm-list gnome org
- Cc:
- Subject: Re: [OFF] Convert int to ustring
- Date: Sun, 30 Oct 2005 12:04:50 +0100
Of course this is not a speedy solution but it is much safer than using
sprintf.
Please find here what Herb Sutter wrotes about string formatters:
http://gotw.ca/publications/mill19.htm
--- Quote ----
From Table 1 I'll extract the following guidelines, also summarized in
Table 2:
- /If all you're doing is converting a value to a string/ (or, for
that matter, to anything else!): Prefer using boost::lexical_cast by
default.
- /For simple formatting, or where you need wide string support or
templatability:/ Prefer using stringstream or strstream; the code will
be more verbose and harder to grasp than it would be with snprintf(),
but for simple formatting it won't be too bad.
- /For more complex formatting, and where you don't need wide string
support or templatability:/ Prefer using snprintf(). Just because it's
C doesn't mean it's off limits to C++ programmers!
- /Only if actual performance measurements show that any of the above
is really a bottleneck at a specific point in your code:/ In those
isolated cases only, instead of the above consider using whichever one
of the faster alternatives strstream or snprintf() makes sense.
- Never use sprintf().
---Quote ----
I've used stringstream to show him a way. But I personally prefer
boost::lexical_cast<>,
Wince I didn't know if he's using or he wants using boost I didn't
suggested that.
BR
Vinzenz 'evilissimo' Feenstra
Nickolai Dobrynin schrieb:
Are you sure this solution is adequate speedwise? Unless there has been an
improvement recently, the stringstream support seems fairly slow, on gcc
at least.
Would it make more sense to use sprintf instead?
Regards,
Nickolai
On Sun, Oct 30, 2005 at 01:56:10AM +0200, Vinzenz 'evilissimo' Feenstra wrote:
#include <sstream>
int num = 1000;
Glib::ustring str;
std::stringstream strstr;
strstr << num;
strstr >> str;
Now str contains a string "1000"
Jupercio Juliano schrieb:
Hi all.
Sorry for the off and the newbie question, but I need to know how
to convert an int to ustring.
Thanks for any help.
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]