Solved

CString & Number Conversions

Posted on 1998-10-21
4
517 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 107
Error on moodle after upgrade 3 149
sumDigits challenge 9 172
haveThree challenge 22 123
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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