Re: [gtkmm] Glib::ustring -> int
- From: "Robert J. Hansen" <rjhansen inav net>
- To: "Benjamin A. Cooper" <bacooper bacwater net>
- Cc: gtkmm-list gnome org
- Subject: Re: [gtkmm] Glib::ustring -> int
- Date: 04 Sep 2002 03:41:49 -0500
> How do I get an int from the string (and a float as well)?
First: you don't. atoi() is part of C++'s C legacy; there are better
ways to do the same task in C++.
Second: use ustring::raw(). It will return a const std::string
reference. You can then throw it into a stringstream and get it back
out again later as an int. Code snippet follows.
=====
Glib::ustring myASCIIdata("123456");
std::stringstream s;
long result;
s << myASCIIdata.raw();
s >> result;
=====
Presto. myASCIIdata has been fed into a stringstream and extracted
again into result. If you're comfortable with stringstreams, this is by
far the preferred solution.
--
Geek Code: GAT d- s+:+ a27 C++(+++)$ ULB++>++++ P++ L+++>++++ E W+ N+ w
PS+ PE++ Y++ PGP++ t+ 5++ X-- R tv b+++ DI++ D--- G+ e++ h*
r* y+*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]