My Program is a simple function calculator. The user is asked to provide two inputs. The program is to run the inputs through a function and spit out the answer as a float type. My problem lies with trying to display the results at the bottom of my frame/window. I tried using wxStaticText but the problem was that a variable could not be the value, or text displayed. Any tips, suggestion, and/or solutions. Thank you for your time :)
If you do use std::to_string (which requires a patch for MinGW, last I heard?) you need to do a bit more work to convert the resultant std::string to a wxString:
The wxT macro is provided to convert string literals to wxStrings. It is just the wxWidgets version of the Visual Studio _T() macro.
To convert a std::string to a wxString you need to use a wxString constructor:
From from wxWidgets 2.9
1 2 3
std::string stlstring = "Hello world";
// assuming your string is encoded as the current locale encoding (wxConvLibc)
wxString mystring(stlstring);
With earlier versions of wxWidgets
1 2 3
std::string stlstring = "Hello world";
// assuming your string is encoded as UTF-8, change the wxConv* parameter as needed
wxString mystring(stlstring.c_str(), wxConvUTF8);
Guys I appreciate the responses, but my problem lies in displaying the results in a wxFrame. The idea is that the float value, upon being calculated, would be displayed, using a static text, in a result section on the bottom of the frame. I tried to use the float as the value of the wxStaticText but the compiler does not recognize or will not accept the float as the text for the static text element. In order to figure out the parameters of the static text element, I created a blank wxString and assigned some text to it. When substituted for the wxT it once again failed to compile.
wxStaticText *fr = new wxStaticText(panel, -1, wxT("f"), wxPoint(90,200)); // "f" is the value printed on the bottom of the screen
I want to substitute "f" with a float value.
wxStaticText *fr = new wxStaticText(panel, -1, some float variable, wxPoint(90,200)); // the goal is to print the numerical value of the variable