Solved

CString & Number Conversions

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 130
ORA-01403: no data found 43 101
has22 challenge 11 95
twoTwo  challenge 35 103
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

810 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