• 如何使用 window api 转换字符集?


    //宽字符转多字节
    std::string W2A(const std::wstring& utf8)
    {
    	int buffSize = WideCharToMultiByte(CP_ACP, NULL, utf8.c_str(), -1, NULL, NULL, NULL, FALSE);
    	char *gbk = new char[buffSize+1];
    	memset(gbk, 0, buffSize + 1);
    	WideCharToMultiByte(CP_ACP, NULL, utf8.c_str(), -1, gbk, buffSize, NULL, FALSE);
    	std::string result(gbk);
    	delete[] gbk;
    	gbk = nullptr;
    	return result;
    }
    
    //多字节转宽字符
    std::wstring A2W(const std::string& gbk)
    {
    	int buffSize = MultiByteToWideChar(CP_ACP, NULL, gbk.c_str(), -1, NULL, NULL);
    	wchar_t* utf8 = new wchar_t[buffSize+2];
    	memset(utf8, 0, buffSize + 2);
    	MultiByteToWideChar(CP_ACP, NULL, gbk.c_str(), -1, utf8, buffSize);
    	std::wstring result(utf8);
    	delete[] utf8;
    	utf8 = nullptr;
    	return result;
    }
    
  • 相关阅读:
    disabled
    C# 实例化顺序
    session问题
    Node js文件系统
    Node js WEB模块
    Node js GET POST请求
    Node js路由
    Node js函数
    Node js模块系统
    Node js 安装+回调函数+事件
  • 原文地址:https://www.cnblogs.com/cheungxiongwei/p/7909864.html
Copyright © 2020-2023  润新知