2

wcstombs have three args.

WideCharToMultiByte have eight args.,

How to replace?

How use wcstombs write like that :

int kk = WideCharToMultiByte(936, 0, szBn, ccBn+1, 0, 0, 0, 0);

How use wcstombs write like that :

int kk= WideCharToMultiByte(936,
                            0,
                            szBn,
                            ccBn+1,
                            kkburr,
                            (ccBn+1)*sizeof(wchar_t),
                            0,
                            0)

Does it same?

hmjd
  • 120,187
  • 20
  • 207
  • 252
cuichang
  • 59
  • 1
  • 8
  • Not the same thing, you can't specify a locale or codepage with wcstombs(), you only get the default locale. What are you *really* trying to do? – Hans Passant May 25 '12 at 10:25
  • 2
    Maybe [this question](http://stackoverflow.com/questions/6300804/wchars-encodings-standards-and-portability) of mine is of some interest for you. – Kerrek SB May 25 '12 at 10:33
  • The WideCharToMultiByte code is run on Pc. Then I want to run the code on Mac ,so I need to Remove the WideCharToMultiByte,because it not run on Mac. – cuichang May 25 '12 at 10:46
  • @cuichang: Not possible to do that with an one-liner. – Jon May 25 '12 at 12:10

2 Answers2

3

WideCharToMultiByte does something much different than wcstombs, so it's at least somewhat doubtful¹ that this replacement would be successful.

Specifically, WCTMB converts from UTF-16 to another character set (and encoding) of your choice. wcstombs converts from a "wide character string" to a "multibyte string", but the standard leaves the exact definition of these terms to the implementor.

In other words: WCTMB converts from a known encoding to another known encoding. wcstombs converts from an unknown encoding to another unknown encoding. You cannot replace the former with the latter, especially if you want to convert to a Chinese encoding (isn't that what 936 is?).

What's the reason for seeking to do this replacement? Whatever it may be, it's almost certain that there are more appropriate ways to achieve the goal.

Update: If you want a platform-independent, reliable solution then I 'd recommend ICU. Don't expect to find an one-line replacement for WCTMB because it simply doesn't exist.


¹ massive understatement

Jon
  • 428,835
  • 81
  • 738
  • 806
0
  • The resulting encoding that wcstombs converts to depends on the current locale while WideCharToMultiByte can be explicitly given a codepage.
  • wcstombs converts from "wide character string", which encoding depends on the implementation of the standard library. WideCharToMultiByte converts from the string in UTF-16. Wide characters wcstombs rely upon may not be encoded in UTF-16, but in Windows wide characters are UTF-16.
  • wcstombs is portable, WideCharToMultiByte is not. If your target platform is Windows only then it doesn't matter.
  • WideCharToMultiByte allows to specify a "default character" which will be used instead of characters that can't be represented in target encoding.

So WideCharToMultiByte is much more powerful and is probably used as a backend for wcstombs.

If your current codepage is not 936, then the replacement you ask about is impossible.

Alex Bakulin
  • 1,668
  • 11
  • 17