Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print TCHAR[] on console

Tags:

c++

visual-c++

I'm quite sure that it is a stupid issue but it drives me crazy..

how could i print on the console a TCHAR array?

DWORD error = WSAGetLastError();
TCHAR errmsg[512];
int ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, error, 0, errmsg, 511, NULL);

i need to print errmsg...

like image 495
hara Avatar asked May 11 '10 16:05

hara


Video Answer


1 Answers

It depends on what TCHAR is. If you compile with Unicode enabled, TCHAR is defined as wchar_t. Then you can use std::wcout, for example:

std::wcout << L"Error: " << errmsg << '\n';

If Unicode is not enabled, TCHAR is an ordinary char and you can use the ordinary std::cout:

std::cout << "Error: " << errmsg << '\n';
like image 108
Thomas Avatar answered Oct 14 '22 14:10

Thomas