简体   繁体   中英

How to convert a wxString to Int for using arithmetic operations?

I am new to Wxsmith and C++ I have created a basic UI with 2 text boxes, a static-text and a button. The question is how do i add the 2 values entered in the two text boxes and display it in the static-text when the button is clicked ? In visual Basic all you had to do was :

variable = Val(textbox1.text)

I'm not familiar with wxwidgets, but wxString has a ToLong member function: http://docs.wxwidgets.org/stable/wx_wxstring.html#wxstringtolong

It seems this attempts to convert the string to a long and store it in a location provided, returning true or false to indicate whether it succeeded or failed.

// Created a string up here somewhere
long converted;
if ( myString.ToLong (&converted) )
{ /* Do something with the number */ }
else
{ /* It wasn't a valid number */ }

I note there doesn't seem to be a version for converting directly to int.

Your task can be divided naturally into two parts:

  1. Arranging so that certain code is executed when the button is pressed.

  2. Writing the code to be executed when the button is pressed.

It is not clear from your question which of these you require help with. Perhaps both?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM