开发者

Visual C++: displaying integer in a text Box

开发者 https://www.devze.com 2022-12-08 02:48 出处:网络
I want to write int i=4; textBox1->Text = i; But it is giving compilation error for type mismatch. How to do box or typecast this?开发者_如何学编程Sorry for answering the quesition myself. But

I want to write

int i=4;
textBox1->Text = i;

But it is giving compilation error for type mismatch. How to do box or typecast this?开发者_如何学编程


Sorry for answering the quesition myself. But I just got it while searching. There is a very easy method

int i=4;
textBox1->Text = Convert::ToString(i);


Instead you could use: textBox1->Text = i.ToString();.


There is a very easy method

int i=4;
textBox1->Text = ""+i;


You need conversion, not a cast. Use itoa() or itow() depending on whether you compile for Unicode.


if you are using CString you can use Format method, or use old c function itoa

example:

CString str;
str.Format("%d",i); 

also do not forget to call UpdateData method to update the GUI controls


Convert integer to string and set as value for Text.

CString textVal;
textVal.Format(_T("%d"), i);
textBox1->Text = textVal;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号