Convert Unicode to Multibyte

I have a little problem: I want to convert unicode to Multi byte, is there any way

+5
source share
6 answers
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;
}

It should use the current locale to convert the Unicode string. For characters that are not in the code page, '?' used by caracter. Tested with Visual C ++ 2005/2008.

+7
source
+5
source

wcstombs :)

+3

WideCharToMultiByte() .

+1
0
source

All Articles