[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Conversion of CString digits to an int

Posted on 1998-12-28
2
Medium Priority
?
266 Views
Last Modified: 2010-04-02
Does anyone know how to convert digits stored in a CString to an int value?
0
Comment
Question by:Gareon
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 1181157
Try

CString strMyInt ( "123");
int nMyInt;
char* pc;

nMyInt = (int) strtol ( (LPCTSTR) strMyInt, &pc, 10);

if ( *pc)
{
// error
}

0
 
LVL 86

Expert Comment

by:jkr
ID: 1181158
Ooops - to elaborate a bit on 'strtol()'
--> begin quote

long strtol( const char *nptr, char **endptr, int base );

The strtol function converts nptr to a long. strtol stops reading the string nptr at the first character it cannot recognize as part of a number. This may be the terminating null character, or it may be the first numeric character greater than or equal to base.
<-- end quote
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

873 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