我基本上试图在 Visual Studio 2008 中编写一个基本转换器,并且我有 2 个文本框,一个从用户获取输入,另一个给出结果输出。当我按下按钮时,我希望第一个文本框中的输入乘以 4.35,然后显示在第二个文本框中。这是到目前为止我在按钮代码中的代码:
String^ i1 = textBox1->Text;
float rez = (i1*4.35)ToString;
textBox2->Text = rez;
但是我收到这些错误:
f:\microsoft visual studio 9.0\projects\hellowin\hellowin\Form1.h(148) : error C2676: binary '*' : 'System::String ^' does not define this operator or a conversion to a type acceptable to the predefined operator
f:\microsoft visual studio 9.0\projects\hellowin\hellowin\Form1.h(148) : error C2227: left of '->ToString' must point to class/struct/union/generic type
f:\microsoft visual studio 9.0\projects\hellowin\hellowin\Form1.h(149) : error C2664: 'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'float' to 'System::String ^'
请帮助我,从 C++ 的文本框中获取一些输入是多么困难,我快要疯了。我已经用谷歌搜索了我遇到的每个错误,但没有出现任何有用的结果,我已经搜索答案一个小时了,请帮忙。
为你解决它,
String^ i1 = textBox1->Text;
float rez = (float)(Convert::ToDouble(i1)*4.35);
textBox2->Text = rez.ToString();
基本上,您希望将字符串转换为实际数字,进行数学计算,然后将其恢复为字符串以用于显示目的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)