C++ – Convert CString into int

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;
}


 

Here is what you get.

Done =)

Reference:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.