gpt4 book ai didi

c++ - TCHAR[] 转换为字符串

转载 作者:行者123 更新时间:2023-11-30 19:48:28 27 4
gpt4 key购买 nike

我想将 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

最佳答案

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

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

关于c++ - TCHAR[] 转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18469457/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com