x
Solved

# Conversion of CString digits to an int

Posted on 1998-12-28
Medium Priority
265 Views
Does anyone know how to convert digits stored in a CString to an int value?
0
Question by:Gareon
[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
• 2

LVL 86

Accepted Solution

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

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

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
###### Suggested Courses
Course of the Month15 days, 8 hours left to enroll