使用 wxString 的 WxWidget
我正在上计算机科学课程,我们必须使用 GUI 制作一个计算器。不过,我一直在用头撞墙,试图获得意见。 了解如何使用指针和 GetValue(),将输入作为 wxString 接收,但这对我没有好处,如果我无法将字符串作为双精度或整数获取,那么我无法对其执行操作。 有谁知道如何将 wxString 转换为 Double?甚至是整数?
提前致谢
I'm taking a computer sciences 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,有两个函数 ToDouble 和 ToLong。
详细内容请查看官方文档:
http://docs.wxwidgets.org/stable/wx_wxstring.html#wxstringtolong
http://docs.wxwidgets.org/stable/wx_wxstring.html#wxstringtodouble
编辑:示例:
请注意:只有输入数字才有效。如果您输入像 2+3 这样的术语,该函数应该返回 false。在这种情况下,您必须拆分字符串并单独解释所有数字。
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:
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.