Click here to Skip to main content
15,886,786 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hai and a very good morning / afternoon/ evening to all of the user of codeguru,, i would like to ask bout how to use the operation of .format();

i tried to convert DWORD to CString

currently using visual studio 2010, making project of MFC

here is the sample code that i have done,
C++
// sample of my code

DWORD abc;

CString temp;

temp.format("%x", abc); // there is an error at the "."

while i m using other format of .format();
it run properly, but did not give out the answer as what it propose to be, while when i re-run it, the answer keep on changing~

DWORD def;

CString ghi;

ghi.temp(_T("%x", def));
Posted
Updated 23-Mar-13 14:57pm
v4

btw guys.. i would like to ask bout..
what is '_T'??
 
Share this answer
 
Comments
JF2015 4-Sep-12 2:39am    
See here:
http://msdn.microsoft.com/en-us/library/se784sk6.aspx
See this code which is working. You must also make sure to initialize "abc" before using the variable.
// sample of my code
DWORD abc = 12345; 
CString temp; 
temp.Format(_T("%lu"), abc);

AfxMessageBox(temp);
 
Share this answer
 
format used is wrong. %lu is the right one when you convert DWORD to CString.

C++
temp.format("%lu", abc); 


On conversion CString to DWORD the effective error free approach would be:

C++
abc= atol((char*)(LPCTSTR)temp);


Now you can verify both conversions.

Thanks,

Kuthuparakkal
 
Share this answer
 
awww.. nvm.. i just found out my prob..
"temp.format("%x", abc);" prob was solve after i add 'L' in front of "%x",...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900