How to convert from CString to integer? And Message Boxes
-
-
How to convert from CString to integer? and Vise versa? Also, how can I display integer in message boxes? I keep getting errors, or are they always CString types? I'm just learning MFC, so bear with me,And sorry if my questions are stupid :sigh: --Star
Here's a possible method for each direction...
int i = 12345;
CString str;// Convert integer i to string in str
str.Format(_T("%d"), i);// Convert string in str to integer i
// (_tstoi is generic text mapping for atoi()/_wtoi() RTL functions)
i = _tstoi(str);For MessageBox, I'm not sure which one you are using - MFC, Windows API, etc. but you can format strings pretty much the same for all of them...
int i = 12345;
CString str;str.Format(_T("The value of i is %d"), i);
int MessageBoxRet = AfxMessageBox(str, MB_ICONEXCLAMATION | MB_OK);"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Here's a possible method for each direction...
int i = 12345;
CString str;// Convert integer i to string in str
str.Format(_T("%d"), i);// Convert string in str to integer i
// (_tstoi is generic text mapping for atoi()/_wtoi() RTL functions)
i = _tstoi(str);For MessageBox, I'm not sure which one you are using - MFC, Windows API, etc. but you can format strings pretty much the same for all of them...
int i = 12345;
CString str;str.Format(_T("The value of i is %d"), i);
int MessageBoxRet = AfxMessageBox(str, MB_ICONEXCLAMATION | MB_OK);"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
How to convert from CString to integer? and Vise versa? Also, how can I display integer in message boxes? I keep getting errors, or are they always CString types? I'm just learning MFC, so bear with me,And sorry if my questions are stupid :sigh: --Star
And also you can use of
wsprintf
.
WhiteSky