65,211
社区成员
发帖
与我相关
我的任务
分享
#include "iostream"
#include "fstream"
#include "windows.h"
using namespace std;
int main()
{
ifstream ifile("test.txt");
char szUTF8[128];
ifile.getline(szUTF8, 128);
int nLen = MultiByteToWideChar( CP_UTF8, 0, szUTF8, -1, NULL, NULL );//得到UTF8编码的字符串长度,是2
LPWSTR lpwsz = new WCHAR[nLen];
MultiByteToWideChar( CP_UTF8, 0, szUTF8, -1, lpwsz, nLen );//转换的结果是UCS2格式的价值两个字
cout<<lpwsz<<endl;
delete[] lpwsz;
return 0;
}