C++ – Print CString to cout

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

	// Terminate the program:
	return 0;


You will get the following output.


Please note that you have to include atlstr.h before you can utilize the CString object.

Done =)

Reference: CString will not go to cout

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 )

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.