Re: Glib::ustring conversion
- From: "Marco Scholten" <mscholtn xs4all nl>
- To: "cyril ponsan" <kikiloizo hotmail com>
- Cc: gtkmm-list gnome org
- Subject: Re: Glib::ustring conversion
- Date: Thu, 30 Jun 2005 13:54:36 +0200
----- Original Message -----
From: "cyril ponsan" <kikiloizo hotmail com>
To: <gtkmm-list gnome org>
Sent: Tuesday, June 28, 2005 9:47 PM
Subject: RE: Glib::ustring conversion
Hello,
i use this method to convert int or double in a string so it should work
for ustring ;)
string convertIntToString(int result)
{
char buffer[100];
sprintf(buffer, "%d", result);
string str = buffer;
return str;
}
my version:
template <typename T>
string ToString( T number, int precision = -1 )
{ ostringstream oss;
if (precision != -1)
{ oss.flags(ios_base::fixed);
oss.precision(precision);
}
oss << number;
return oss.str();
}
and for string to int :
int stringToInt(string str)
{
char buffer[100];
int nb;
strcpy(buffer, str.c_str());
nb = atoi(buffer);
return nb;
}
or a bit shorter
int ToInt(string s)
{ return atoi(s.c_str());
}
--
Marco
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]