Re: [gtkmm] Glib::ustring -> int



> 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]