-1

我想转换TCHAR nameBuf[]string.

TCHAR nameBuf[MAX_COMPUTERNAME_LENGTH + 2];

DWORD nameBufSize;

nameBufSize = sizeof nameBuf - 1;

GetComputerName(nameBuf, &nameBufSize); //store computer name into nameBuf

_tprintf(_T("%s"), nameBuf); //print the computer name
4

2 回答 2

0

让我们明确类型。请参阅下面的修改代码:

WCHAR nameBuf[MAX_COMPUTERNAME_LENGTH + 2];

DWORD nameBufSize;

nameBufSize = sizeof nameBuf - 1;

GetComputerNameW(nameBuf, &nameBufSize); //store computer name into nameBuf

wprintf_s(L"%s", nameBuf); //print the computer name
于 2013-08-27T15:26:55.497 回答
0

如果你想使用窄字符(看起来像你这样做)那么这段代码

char nameBuf[MAX_COMPUTERNAME_LENGTH + 2];
DWORD nameBufSize;
nameBufSize = sizeof nameBuf - 1;
GetComputerNameA(nameBuf, &nameBufSize); //store computer name into nameBuf
printf_s("%s", nameBuf); //print the computer name
string NAME = nameBuf;

未经测试的代码

于 2013-08-27T16:03:19.367 回答