CString & Number Conversions


Any good way to convert number (e.g. UINT, int etc) to CString & vice-versa..... Right now, my method is
int i = 30;
CString cStr;
char str[10];

cStr = str;

Which I find is not good becos I need to use a char array....

Who is Participating?
visualcConnect With a Mentor Commented:
From number to string:
 - you can use all facilitys of from sprintf when you are using
CString.Format() method of CString class.
 -  call this member function to write formatted data to a CString in the same way that sprintf formats data into a C-style character array.
From string to number:
 -these following  routines convert data from one form to another. Generally these routines execute faster than conversions you might write. Each routine that begins with a to prefix is implemented as a function and as a macro.

Routine                                        Use

atof                                               Convert string to float
atoi, _atoi64                                 Convert string to int
atol                                               Convert string to long
strtod, wcstod                              Convert string to double
strtol, wcstol                                 Convert string to long integer
strtoul, wcstoul                 Convert string to unsigned longinteger

Just use CString.Format( ...)
CString -> int:

int -> CString:
   int i = atoi(cStr);

sorry, just swap the arrows <-
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.