tags:

views:

401

answers:

4

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?

A: 

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

sharptooth
These dont work in Visual C++. It says "Cannot convert from char * to String ^
avd
I guess you are writing managed C++
aJ
WHat is managed C++? I am workin in VC++ 2005
avd
A: 

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

Ahmed Said
A: 

Convert integer to string and set as value for Text.

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

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);
avd
You are using managed c++ thus you need to look at the .Net libraries
Mark