Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to cast integer->CString?

Status
Not open for further replies.

boybles

IS-IT--Management
May 17, 2001
2
US
The following casting method compiles correctly, but doesn't seem to work. I want to cast an integer value into a CString. Can anybody help?

-Boybles

int testint=1;
CString testcstring;
testcstring=(CString)testint;
 
You may see CString::CString constructors in MSDN. And all of them don't receive int by way of parameter!
If you want to convert int to CString, you may type following:
--------------
int nTest = 5;
CString sTest;
sTest.Format(_T("%d"), nTest);
--------------
or to convert to LPTSTR:
--------------
TCHAR szTest[4];
_itot(nTest, szTest, 10);
--------------
 
there is a simple way of fixing it It Java and I think the same applies in C++

testcstring = " " + testint;

Forgive me if it doesn't work my C++ has gone a bit rusty.

Regards.
 
you should use:

char* char;
...

_itoa(testint,char,10);
CString myString(char);

Hope of being of some help,s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Actually, it would be much easier to do:
CString testcstring(testint + '0')
if you ask me! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top