WxWidgets using wxString
I'm taking a computer sc开发者_StackOverflow中文版iences class and we have to make a calculator using a GUI. I have been banging my head into a wall trying to even get input though. Understand how to use pointers and GetValue(), to take in the input as a wxString but that does me no good, If I can't get the string as a double or integer then I can't perform operations on it. Does anyone know how to convert wxString to Double? or even int?
Thanks in Advance
For this purpose, there are the two functions ToDouble and ToLong.
For details take a look at the offical documentation:
http://docs.wxwidgets.org/stable/wx_wxstring.html#wxstringtolong
http://docs.wxwidgets.org/stable/wx_wxstring.html#wxstringtodouble
EDIT: Example:
wxTextCtrl ctrl;
// user has entered a number
double number;
if( !ctrl.GetValue().ToDouble( &number ) )
// handle error
else
// continue...
Please note: It will only work if you enter a number. If you enter a term like 2+3 the function should return false. In this case you have to split the string up and interpret all numbers seperately.
精彩评论