Solved

CString & Number Conversions

Posted on 1998-10-21
4
513 Views
Last Modified: 2013-11-20
Hi

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];

sprintf(str,"%d",i);
cStr = str;
============

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




0
Comment
Question by:samyee
  • 2
4 Comments
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1323685
Just use CString.Format( ...)
0
 
LVL 1

Expert Comment

by:fkurucz
ID: 1323686
CString -> int:
   cStr.Format("%d",i);

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

0
 
LVL 1

Expert Comment

by:fkurucz
ID: 1323687
sorry, just swap the arrows <-
0
 

Accepted Solution

by:
visualc earned 20 total points
ID: 1323688
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

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now