本文介绍了将Unicode转换为多字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有smalll的问题我想转换unicode成多字节有什么办法
I have smalll problem i want to convert unicode into Multi byte is there any way
推荐答案
std::string NarrowString(const std::wstring& str, const char* localeName = "C")
{
std::string result;
result.resize(str.size());
std::locale loc(localeName);
std::use_facet<std::ctype<wchar_t> >(loc).narrow(
str.c_str(), str.c_str() + str.size(), '?', &*result.begin());
return result;
}
它应该使用当前语言环境转换unicode字符串。对于不属于代码页的字符,正在使用?字符。使用Visual C ++ 2005/2008测试。
It should use the current locale to convert the unicode string. For the caracters that do not belong in the codepage the '?' caracter is being used. Tested with Visual C++ 2005/2008.
这篇关于将Unicode转换为多字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!