发布网友 发布时间:2022-04-23 10:08
共1个回答
热心网友 时间:2023-10-10 22:03
其实 linux 和 windows 的系统函数都是C函数,并且提供了GB2312toUTF-8的函数,所以C语言是可以实现转码的。以下是windows的例子:int num = ::MultiByteToWideChar(CP_ACP, 0, "你好", -1, NULL, 0);wchar_t* m_arrayShort = new wchar_t[num];::MultiByteToWideChar(CP_ACP, 0, "你好", -1, m_arrayShort, num); int len = ::WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)m_arrayShort, num, 0, 0, NULL, NULL);char *tmpPT = new char[len+1];::WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)m_arrayShort, num, tmpPT, len, NULL, NULL);tmpPT[len] = 0;