Solved

Conversion of CString digits to an int

Posted on 1998-12-28
2
260 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 50 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
IdTelnet1DataAvailable handler freezes the Application 4 84
typedef std::deque<BYTE> ByteVector is broken in vs2012 23 87
thread-safe code in c++ 2 115
Best book to learn C++ 4 83
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

789 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