Re: wprintf() could not display unicode chars which is > 255 to console?
- From: David Wilkinson <no-reply@xxxxxxxxxxxx>
- Date: Sun, 15 Jan 2006 17:15:45 -0500
Mihai N. wrote:
Why use something as dead-obsolete as wprintf anyway? Use CString::Format instead.
wprintf was a kludge for 16-bit Windows and is maintained only for backward
compatibility with obsolete code.
wprintf is ANSI C, not obsolete. It deals with Unicode strings, which where not even there in Windows 16-bit, so I think you are counfusing it with something else.
For Unicode console output, CString::Format, wprintf or wcout are equivalent, the limitations belong to the console.
On the other side, I agree that if you don't need cross-platform code, CString::FormatMessage is better, because it does allow to change the order of the placeholders without changing the order of the parameters.
This is good for internationalization.
CString::Format and printf are equivalent, and cout (iostream) is a crap, which encourages concatenation.
===================================================================
This is not directed to Joe, but to whoever thinks iostream is ok:
-------------------------------------------------------------------
C++ die-hards will complain here, and I know iostream is type-safe (unlike the other options). But is a mess to use for internationalization.
If you really want "C++ purity", then you can go with boost format library.
And before attaking me on this, read the two topics on string formatters in "Exceptional C++ Style" :-)
-------------------------------------------------------------------
Mihai:
I have to say that this thread seems to be confusing outputting to a console window with formatting strings.
To format a string, in a non-Unicode app, the following are alternative methodologies:
CString::Format() sprintf std::ostringstream
and for a Unicode app
CString::Format() swprintf std::wostringstream
If we make the typedef
typedef std::basic_ostringstream<TCHAR> tostringstream;
then we have generic alternatives
CString::Format() _stprintf tostringstream
What is better about any of these three as opposed to the others? Personally, I see no reason to choose non-portable code in a pure console application, so I would always go the iostream route. I do not have the book "Exceptional C++ style"; what does it have to say here? I can see that tostringstream might lose on efficiency (usually not an issue), but why is it worse for internationalization?
The question of writing wide characters to the console is a separate question, I think. I have never written a console app using wide characters, so I have no opinion. But I have to say I am shocked if Win2000/XP cannot output a correctly formatted wide-character string to the Console, using either wcout or wprintf. Referring to your other post, what does backward compatibility have to do with this? Apart from the UTF-16/UCS-2 issue, there has only ever been one kind of wide character string in NT/2000/XP.
David Wilkinson
.
- Follow-Ups:
- References:
- wprintf() could not display unicode chars which is > 255 to console?
- From: David
- Re: wprintf() could not display unicode chars which is > 255 to console?
- From: Joseph M . Newcomer
- Re: wprintf() could not display unicode chars which is > 255 to console?
- From: Mihai N.
- wprintf() could not display unicode chars which is > 255 to console?
- Prev by Date: Re: How redistribute MFC applicationn that use CHtmlView
- Next by Date: Re: can't send message to other process
- Previous by thread: Re: wprintf() could not display unicode chars which is > 255 to console?
- Next by thread: Re: wprintf() could not display unicode chars which is > 255 to console?
- Index(es):
Relevant Pages
|