转换Unicode和ANSI文字

转换Unicode和ANSI文字
wcstombs_s、mbstowcs_s 函数原型参考MSDN。
根据MSDN上的例子修改:
1 char szDest[BUFFER_SIZE] = {0}; 2 wchar_t* pwszSrc = L"你好"; 3 size_t uiLen; 4 5 // 如果没有这一句话,中文显示不正确 6 _tsetlocale(LC_ALL,_T("")); 7 8 wcstombs_s(&uiLen, szDest, (size_t)BUFFER_SIZE, pwszSrc, (size_t)BUFFER_SIZE); 9 10 cout << " Characters converted: " << uiLen << endl 11 << " Multibyte character: " << szDest << endl; 12 13 wchar_t wszDest[BUFFER_SIZE] = {0}; 14 char* pszSrc = "我也好"; 15 mbstowcs_s(&uiLen, wszDest, (size_t)BUFFER_SIZE, pszSrc, (size_t)BUFFER_SIZE); 16 17 cout << " Characters converted: " << uiLen << endl 18 << " byte character: " << szDest << endl;

你可能感兴趣的:(转换Unicode和ANSI文字)