Output CString type with std::cout and printf

CString is a MFC class and it’s under unicode.

When using standard stream to output it, use std::wcout instead of std::cout becuase it’s wide charaters. Also, use cstr.GetBuffer() instead of cstr. Or LPCTSTR(cstr) should work the same.
Example:


CString str1, str2;
std::wcout << “str1: “ << str1.GetBuffer() << std::endl << “str2: “ << str2.GetBuffer() << std::endl;



When using printf, use %S instead of %s should do the job.
2016/2/13 22:05