码迷,mamicode.com
首页 > 其他好文 > 详细

ws2s函数

时间:2015-05-13 16:08:50      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

std::string ws2s(const std::wstring& str)
{
    char*     pElementText;
    int    iTextLen;
    // wide char to multi char
    iTextLen = WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, NULL, 0, NULL, NULL);
    pElementText = new char[iTextLen + 1];
    memset((void*)pElementText, 0, sizeof(char)* (iTextLen + 1));
    ::WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL);
    std::string strText;
    strText = pElementText;
    delete[] pElementText;
    return strText;
}
std::string strKEy = ws2s(pKey);//pKey为WCHAR类型
    char pStr[256] = {0};
    strcpy_s(pStr, 256, strKEy.c_str());

 

ws2s函数

标签:

原文地址:http://www.cnblogs.com/wumac/p/4500576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!