Click to See Complete Forum and Search --> : How to convert a Cstring into a int ?


parragain
May 19th, 1999, 02:13 PM
I would like to know how to convert a Cstring into a int.
Thanks a lot

Philippe.

Erich Ruth
May 19th, 1999, 02:25 PM
int value;

sprintf(value, "%i", strText);

rocky
May 19th, 1999, 02:27 PM
use the function atoi(). (ascii to int)
for example:
CString string = "40";
int zahl = atoi(string); // converts string to int

...this should help you.

parragain
May 19th, 1999, 02:33 PM
Danke sehr Rocky.

sanjay
May 20th, 1999, 02:52 AM
CString l_str;
int l_iVar;

l_str.Format("%d", l_iVar);

hope this should help you.


Regards,
Sanjay
sanjaypavangp@hotmail.com

May 20th, 1999, 05:52 AM
int sprintf( char *buffer, const char *format [, argument] ... );

This is the prototype for sprintf function.

So your the code below won't compile at all.
Also, you are not doing exactly what the question is.


int value;

sprintf(value, "%i", strText);

srini_raghav
May 20th, 1999, 08:24 AM
use atoi(CString ) to convert a CString object to an integer....
Thanks lot,
Srini

ctyuang
May 21st, 1999, 04:43 AM
you can use function strcpy(CString, char) to convert the Cstring to character first, and then use function atoi(*char ) to convert the character to int.

CString---->Character----->interger

email me to let me know your progress

ty