本文介紹了如何在 C++ (Unicode) 中將 std::string 轉換為 LPCWSTR的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在尋找將 std::string 轉換為 LPCWSTR 的方法或代碼片段
I'm looking for a method, or a code snippet for converting std::string to LPCWSTR
推薦答案
感謝提供指向 MSDN 文章的鏈接.這正是我要找的.??p>
Thanks for the link to the MSDN article. This is exactly what I was looking for.
std::wstring s2ws(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
std::wstring stemp = s2ws(myString);
LPCWSTR result = stemp.c_str();
這篇關于如何在 C++ (Unicode) 中將 std::string 轉換為 LPCWSTR的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!