Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/MFC
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,
// 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 3-Sep-12 17:50pm
xnold494
Edited 23-Mar-13 15:57pm
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

format used is wrong. %lu is the right one when you convert DWORD to CString.
 
temp.format("%lu", abc); 
 
On conversion CString to DWORD the effective error free approach would be:
 
abc= atol((char*)(LPCTSTR)temp);
 
Now you can verify both conversions.
 
Thanks,
 
Kuthuparakkal
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

awww.. nvm.. i just found out my prob..
"temp.format("%x", abc);" prob was solve after i add 'L' in front of "%x",...
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

btw guys.. i would like to ask bout..
what is '_T'??
  Permalink  
Comments
JF2015 at 4-Sep-12 2:39am
   
See here:
http://msdn.microsoft.com/en-us/library/se784sk6.aspx

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 555
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 23 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100