Byte conversion, digital conversion string

Character and Numeric Conversion
TCHAR buff[100];
// 2. Numeric characters turn
// sprintf(); wsprintf() ,_stprintf()
_stprintf_s(buff,_T("%d"), number);
// 3. String integer conversion
// sscanf_s(); swscanf_s(), _stscanf_s();
int number2 = 0;
_stscanf_s(buff, _T("%d"), &number2);
MessageBox(NULL, buff, 0, 0);
return 0;
}
Multi-byte wide byte conversion
// wide character to a multi-character (Unicode -> ASCII) 
#define WCHAR_TO_CHAR(lpW_Char, lpChar) \
WideCharToMultiByte(CP_ACP, NULL, lpW_Char, -1, \
lpChar, _countof(lpChar), NULL, FALSE);
// multi-character converted to wide characters (ASCII -> Unicode) 
#define CHAR_TO_WCHAR(lpChar, lpW_Char) \
MultiByteToWideChar(CP_ACP, NULL, lpChar, -1, \
lpW_Char, _countof(lpW_Char));
// 4. Multibyte wide and byte conversion
char * szChar = "hello 15pb";
wchar_t szWchar[100];
char szBuff[100];
// multi-byte wide transfer byte
CHAR_TO_WCHAR(szChar, szWchar);
MessageBoxW(NULL, szWchar, NULL, NULL);
// wide byte conversion multibyte
WCHAR_TO_CHAR(szWchar, szBuff);
MessageBoxA(NULL, szBuff, NULL, NULL);

 

Reproduced in: https: //www.cnblogs.com/mtbook/p/11021142.html

Guess you like

Origin blog.csdn.net/weixin_33920401/article/details/93155022