problem with converting CString to int
-
now i have a CString variable contain an integer value i wanna convert the CString to int so i used atoi() function
CString strNumber = "00123" int nNumber = atoi(strNumber);
then nNumber will contain (123)and it ignore the Zeros so what if i need these Zeros, what should i do also if i wroteint x = 0110;
x will result into (72) could anybody explain that thnx 4 ur time and concern -
now i have a CString variable contain an integer value i wanna convert the CString to int so i used atoi() function
CString strNumber = "00123" int nNumber = atoi(strNumber);
then nNumber will contain (123)and it ignore the Zeros so what if i need these Zeros, what should i do also if i wroteint x = 0110;
x will result into (72) could anybody explain that thnx 4 ur time and concernhello, In a integer you can't keep the zeros, so if you want the zeros at the left you have to use string and so on, About the second problem, if you put 0 at the left, you are using octal system so, 0110 = 0*8^3+1*8^2+1*8+0 = 72 Regards -- modified at 10:03 Wednesday 11th October, 2006
-
now i have a CString variable contain an integer value i wanna convert the CString to int so i used atoi() function
CString strNumber = "00123" int nNumber = atoi(strNumber);
then nNumber will contain (123)and it ignore the Zeros so what if i need these Zeros, what should i do also if i wroteint x = 0110;
x will result into (72) could anybody explain that thnx 4 ur time and concernsingersinger wrote:
so what if i need these Zeros, what should i do
padding zeros is a display formatting operation and has nothing to do with the value of the intrinsice numeric type (int, long, etc.)
singersinger wrote:
x will result into (72)
if you want x = 110 write:
int x = 110;
otherwise the leading zero is interpreted by the compiler to mean "octal" just as leading 0x means hexadecimal.led mike
-
now i have a CString variable contain an integer value i wanna convert the CString to int so i used atoi() function
CString strNumber = "00123" int nNumber = atoi(strNumber);
then nNumber will contain (123)and it ignore the Zeros so what if i need these Zeros, what should i do also if i wroteint x = 0110;
x will result into (72) could anybody explain that thnx 4 ur time and concernnote: int x; x= 0110; //oct value 0"number", base 8 x= 0x110; //hex value 0x"number", base 16 x= 110; //dec value, base 10 so a 0110(base 8) number is 72(base 10) * use Windows calculator to check the above values you can NOT keep the zeros if you use a "int" type