You can use _wtoi() or _ttoi() to convert a CString into int.
#include "atlstr.h"
#include <iostream>
using namespace std;
int main ()
{
// Create a CString with number
CString intStr = _T("123");
// Convert the CString into int
int aInt = _wtoi(intStr);
// 123 + 123 = 246
aInt += 123;
// Print 246 to cout
cout << aInt << endl;
// Pause
system("PAUSE");
// Terminate the program:
return 0;
}
Continue reading C++ – Convert CString into int →
The following code shows you how to print CString to cout.
#include "atlstr.h"
#include <iostream>
using namespace std;
int main ()
{
// Create a CString
CString cStr = _T("I am a CString.");
// Print the address of cStr only
cout << cStr << endl;
// Print the cStr content
wcout << cStr.GetString() << endl;
// Pause
system("PAUSE");
// Terminate the program:
return 0;
}
Continue reading C++ – Print CString to cout →
Dream BIG and go for it =)