tags:

views:

542

answers:

6

I have smalll problem i want to convert unicode into Multi byte is there any way

+3  A: 

wcstombs works beautifully for me :)

Goz
A: 

There's WideCharToMultiByte winapi function.

Paulius Maruška
+4  A: 

Three options offhand:

ctacke
+1  A: 

In most cases WideCharToMultiByte() will be enough.

sharptooth
A: 

use WideCharToMultiByte

Ahmed Said
+1  A: 
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 the caracters that do not belong in the codepage the '?' caracter is being used. Tested with Visual C++ 2005/2008.

Cristian Adam