Solved

CString & Number Conversions

Posted on 1998-10-21
4
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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