#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
wchar_t* ws = (wchar_t*)L"测试字符串";
char* ss = (char*)"ABC我们";
int bufSize = WideCharToMultiByte(CP_ACP, NULL, ws, -1, NULL, 0, NULL, FALSE);
cout << bufSize << endl;
char* sp = new char[bufSize];
WideCharToMultiByte(CP_ACP, NULL, ws, -1, sp, bufSize, NULL, FALSE);
cout << sp << endl << endl;
delete[] sp;
bufSize = MultiByteToWideChar(CP_ACP, 0, ss, -1, NULL, 0);
cout << bufSize << endl;
wchar_t* wp = new wchar_t[bufSize];
MultiByteToWideChar(CP_ACP, 0, ss, -1, wp, bufSize);
wcout.imbue(locale("chs"));
wcout << wp;
delete[] wp;
}
网友评论