how to type cast from CString to int [modified]
-
please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006
-
please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006
yogendra kaushik wrote:
please any ont tell me how to typa cast from CString to int i get the CString type value from user now i want to convert it in to int for any use so plz tell me how i convert it.
here is one way
int i=atoi(str.GetBuffer()); str.ReleaseBuffer();
Knock out 't' from can't, You can if you think you can :cool: -
please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006
Use _ttoi() function Amar:)
-
please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006
Try this way.
CString strInteger(_T("302")); int iValue = _ttoi(strInteger);
i value will be 302 Appu.. "If you judge people, you have no time to love them." -
please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006
of course you find your answer in atoi and... but see this link i think its goodConverting numeric types to strings and strings to numeric types[^]_**
**_
whitesky
-
yogendra kaushik wrote:
please any ont tell me how to typa cast from CString to int i get the CString type value from user now i want to convert it in to int for any use so plz tell me how i convert it.
here is one way
int i=atoi(str.GetBuffer()); str.ReleaseBuffer();
Knock out 't' from can't, You can if you think you can :cool:Calling
GetBuffer
andReleaseBuffer
is completely unnecessary. The following will work:CString FName = "10"; int n = atoi(FName);
It works becauseCString
has anoperator LPCTSTR
. Steve -
Calling
GetBuffer
andReleaseBuffer
is completely unnecessary. The following will work:CString FName = "10"; int n = atoi(FName);
It works becauseCString
has anoperator LPCTSTR
. SteveStephen Hewitt wrote:
Calling GetBuffer and ReleaseBuffer is completely unnecessary
Ohh...
GetBuffer
andReleaseBuffer
is mostly used where you want to modify data of the CString instead of Format. Knock out 't' from can't, You can if you think you can :cool: -
please any ont tell me how to type cast from CString to int actually i receive the value from user and the value is int type but i used its datatype CString now for futhure operation i want to typecast it to int . so plz tell me how i convert it. Please mail me -- modified at 2:04 Thursday 15th June, 2006
You have recieved several answers to your question and they all show you how to convert a string to integer. Take note that this is not type casting, it is conversion from one form to another. This is important because you could type cast a string to an integer value but the value would not be the value entered in the string. It would take the individule byes and assume they are parts of the final number you are seeking. char str = "AB"; // 'A' = 0x41, 'B' = 0x42 short n = (short*)(str); // n = 0x4241 = 16961 If you are wondering about the reversal of the numbers durring the type casting, then you need to go look up big endian and little endian on the Web. INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra