Solved

CString & Number Conversions

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

832 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