Re: wostream &operator <<(wostream &, string const &)?
peter koch wrote:
kuyper@wizard.net wrote:
"Kristof Zelechovski" wrote:
Uzytkownik "AllanW" <allan_w@my-dejanews.com> napisal w wiadomosci
news:1155062150.001381.325180@h48g2000cwc.googlegroups.com...
"KHitof ?elechovski" wrote:
I am trying to go Unicode with my code base. I noticed
that in most cases I can safely replace cout with wcout
since all standard types behave correctly. However,
all but one. The offender is std::string. I cannot
send it to std::wcout. WHY? If std::string is a
replacement for char const [] and I can send char const
[] to std::wcout, why cannot I do the same with a
std::string?
Have you tried the same with a std::wstring?
Yes, I have. But what does it buy me? Nothing. Because
std::wcout and std::string is what I have.
Well, as long as you have std::string rather than
std::wstring, you haven't converted completely to wide
characters. And as long as you have a mixture of narrow and
wide character types, you're going to have to deal
periodically with converting between them.
This is not necesarily so. You can imagine applications that
use a mix of char and wchar_t strings (the application I
currently work on has this). Some parts of the system has to
access external data that is keyed on 8-bit characters (e.g.
resource files, databases and so on). Even if the application
per se is unicode, this will not be the case for the external
data - ever. So how can I present the data if I can't strem
it to a wide output stream? I believe it is a reasonable
expectation that the conversion is handled automatically.
I think that the *intent* was that for programs using Unicode,
internally, everything would be wchar_t, and externally,
everything would be char, with conversion on the fly in
std::filebuf. That's why a std::wfilebuf reads and writes
char's in the file.
How well this works in practice, I don't know. I do know that
there are systems which support IO directly in wchar_t. I also
know that there are applications which use UTF-8 internally.
Which means that you could conceivably end up doing the
opposite: using char's internally, but wchar_t externally.
--
James Kanze GABI Software
Conseils en informatique orient9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S9mard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]