Bug*_*ter 2 c++ textbox c++-cli
我基本上试图在visual studio 2008中编写一个基本的转换器,我有两个文本框,一个用户输入,另一个用输出结果.当我按下按钮时,我希望第一个文本框中的输入乘以4.35然后显示在第二个文本框中.到目前为止,这是我在按钮代码中的代码:
String^ i1 = textBox1->Text;
float rez = (i1*4.35)ToString;
textBox2->Text = rez;
Run Code Online (Sandbox Code Playgroud)
但是我收到这些错误:
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 ^'
Run Code Online (Sandbox Code Playgroud)
请帮助我疯狂地从C++中的文本框中获取一些输入是多么的荒谬.我用谷歌搜索了我的每一个错误,没有任何有用的信息,我已经找了一个小时的答案,请帮忙.
为你修好,
String^ i1 = textBox1->Text;
float rez = (float)(Convert::ToDouble(i1)*4.35);
textBox2->Text = rez.ToString();
Run Code Online (Sandbox Code Playgroud)
基本上,您希望将字符串转换为实际数字,进行数学运算,然后将其重新转换为字符串以便显示.