CString to std :: cout
3 answers
How to print CString to console? Tried this code but got something as a pointer.
My apologies. I didn't finish and was interrupted. Obviously you need to convert to temporary CStringA (otherwise it is wide format ie wcout). I didn't get it until I read your post (again):
std::ostream& operator << ( std::ostream& os, const CString& str )
{
if( str.GetLength() > 0 ) //GetLength???
{
os << CStringA( str ).GetString();
}
return os;
}
You could, as suggested, just use wcout:
std::ostream& operator << ( std::wostream& os, const CString& str )
{
if( str.GetLength() > 0 ) //GetLength???
{
os << CStringA( str ).GetString();
}
return os;
}
Then use like this:
std::wcout << str << std::endl;
+1
source to share