How Can I convert stringc to int?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
SirSami
Posts: 20
Joined: Mon Mar 24, 2008 2:18 pm
Location: Finland

How Can I convert stringc to int?

Post by SirSami »

I have a problem at converting stringc type file to int. So, I have to get text from editBox and getText() returns stringc type data and I need to convert it to int format for futher use.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

you can use the good old C function atoi(...):

Code: Select all

int val = atoi(txt.c_str());
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Doesn't it return stringw? In that case you can force conversion by putting the c_str() result into a stringc object and get str_c() on that one again. Also, Irrlicht provides a strtol10 method which can convert a char* to an unsigned int, or use fast_atof and cast the result to int (in order to handle also negative numbers).
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

wcstol or wtol do it for wide strings. Of course Irrlicht could choose to implement wstrtol10...

Travis
Post Reply