64,676
社区成员
发帖
与我相关
我的任务
分享
shared_ptr<wstring> MB2WC(const char* buf)
{
int len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return shared_ptr<wstring>(new wstring(L""));
vector<wchar_t> unicode(len);
MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);
return shared_ptr<wstring>(new wstring(&unicode[0]));
}
shared_ptr<wstring> MB2WC(const char* buf)
{
int len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return shared_ptr<wstring>(new wstring(L""));
vector<wchar_t> unicode(len);
MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);
return shared_ptr<wstring>(new wstring(&unicode[0]));
}
shared_ptr<wstring> MB2WC(const char* buf)
{
int len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return shared_ptr<wstring>(new wstring(L""));
vector<wchar_t> unicode(len);
MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);
return shared_ptr<wstring>(new wstring(&unicode[0]));
}
#include <windows.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
wstring MB2WC(const char* buf)
{
int len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return wstring(L"");
vector<wchar_t> unicode(len);
MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);
return wstring(&unicode[0]);
}
int main()
{
char *pszAnsi = "proesignbycoordinate.txt";
wstring ws = MB2WC(pszAnsi);
wcout << ws << endl << (ws.length() == wcslen(ws.c_str())) << endl;
return 0;
}