在c++中转换代码页
Converting Code pages in c++
与c#字符串转换代码(代码页之间)等效的代码是:
public static string Convert(string s)
{
Encoding encoder = Encoding.GetEncoding(858);
return Encoding.Default.GetString(encoder.GetBytes(s));
}
在vc++(不是CLR),例如使用WideCharToMultiByte/MultiByteToWideChar WinAPI函数?
是的,MultiByteToWideChar()
和WideCharToMultiByte()
是等效的Win32函数,例如:
std::wstring Convert(const std::wstring &s)
{
if (s.empty())
return std::wstring();
int len = WideCharToMultiByte(858, 0, s.c_str(), s.length(), NULL, 0, NULL, NULL);
if (len == 0)
throw std::runtime_error("WideCharToMultiByte() failed");
std::vector<char> bytes(len);
len = WideCharToMultiByte(858, 0, s.c_str(), s.length(), &bytes[0], len, NULL, NULL);
if (len == 0)
throw std::runtime_error("WideCharToMultiByte() failed");
len = MultiByteToWideChar(CP_ACP, 0, &bytes[0], bytes.size(), NULL, 0);
if (len == 0)
throw std::runtime_error("MultiByteToWideChar() failed");
std::wstring result;
result.resize(len);
len = MultiByteToWideChar(CP_ACP, 0, &bytes[0], bytes.size(), &result[0], len);
if (len == 0)
throw std::runtime_error("MultiByteToWideChar() failed");
return result;
}
相关文章:
- 用于将C++代码转换为 Web 程序集的脚本未终止
- 如何将 c++ get 函数代码转换为 opencv 算法中使用的 python
- 将 OpenCV 2 中的ANN_MLP代码转换为 OpenCV 3 代码
- 将 c++ 代码转换为 python,使用运算符?
- 使用 jni 将返回带有模板的对象的 Java 代码转换为 c++
- 如何在 Poco 中将工作 HTTP 代码转换为 HTTPS
- 将C++代码转换为 R 代码以生成数据
- 如何将C++ lambda 函数代码转换为 C#?
- 将 python、numpy 和 scipy 代码转换为兼容C++代码?
- 将本机C 代码转换为Java
- 将C++非托管代码转换为 C#
- 将Qt的QML代码转换为C++
- 将此C 代码转换为MIPS
- 如何将此代码转换为两个以上的数字(计算HCF)
- 想要将此 Matlab 代码转换为 OpenCV 代码
- 尝试将 C++11 代码转换为 C++03 时默认函数模板参数出错
- 将阻止同步代码转换为异步
- 将视觉C 代码转换为Borland C 构建器
- 如何将VDT的Pade Exp fast_ex()的双重版本的标量代码转换为SSE2?
- 将 ML 代码转换为 C++