How to convert CString to int MFC 7.1
-
Hi Guys, I am trying to convert a CString to an int in an MFC 7.1 unicode project, but it wont work. Here is what I tried. CString cszNumber = "1234567"; int nNumber = atoi(cszNumber); That didn't compile so I tried this CString cszNumber = "1234567"; int nNumber = _ttoi(cszNumber.GetBuffer(0)); That only brought across the first digit. Any Ideas? This method used to work fine in my old non unicode MFC 6 project. Cheers, Greg
-
Hi Guys, I am trying to convert a CString to an int in an MFC 7.1 unicode project, but it wont work. Here is what I tried. CString cszNumber = "1234567"; int nNumber = atoi(cszNumber); That didn't compile so I tried this CString cszNumber = "1234567"; int nNumber = _ttoi(cszNumber.GetBuffer(0)); That only brought across the first digit. Any Ideas? This method used to work fine in my old non unicode MFC 6 project. Cheers, Greg
-
Hi Guys, I am trying to convert a CString to an int in an MFC 7.1 unicode project, but it wont work. Here is what I tried. CString cszNumber = "1234567"; int nNumber = atoi(cszNumber); That didn't compile so I tried this CString cszNumber = "1234567"; int nNumber = _ttoi(cszNumber.GetBuffer(0)); That only brought across the first digit. Any Ideas? This method used to work fine in my old non unicode MFC 6 project. Cheers, Greg
_ttoi should work without the GetBuffer call, I believe.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
-
Why use scanf? I always prefer to use strtol to accomplish this task. I personally hate scanf so I was wondering why you would recommend it.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
-
Hi Guys, I am trying to convert a CString to an int in an MFC 7.1 unicode project, but it wont work. Here is what I tried. CString cszNumber = "1234567"; int nNumber = atoi(cszNumber); That didn't compile so I tried this CString cszNumber = "1234567"; int nNumber = _ttoi(cszNumber.GetBuffer(0)); That only brought across the first digit. Any Ideas? This method used to work fine in my old non unicode MFC 6 project. Cheers, Greg
And one more thing when use of GetBuffer use of ReleaseBuffer ;)
WhiteSky
-
Hi Guys, I am trying to convert a CString to an int in an MFC 7.1 unicode project, but it wont work. Here is what I tried. CString cszNumber = "1234567"; int nNumber = atoi(cszNumber); That didn't compile so I tried this CString cszNumber = "1234567"; int nNumber = _ttoi(cszNumber.GetBuffer(0)); That only brought across the first digit. Any Ideas? This method used to work fine in my old non unicode MFC 6 project. Cheers, Greg
Or you could use the "Generic-Text Routine Mappings" These will work on both Unicode and non-Unicode builds. CString cszNumber = _T("1234567"); int nNumber = _tstoi(cszNumber);
"Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")