Re: std::cout << Glib::ustring(utf8_literal) throws exception



Murray Cumming wrote:
On Sun, 2008-07-13 at 00:48 -0700, Sohail Somani wrote:
Murray Cumming wrote:
On Sat, 2008-07-12 at 19:15 -0700, Sohail Somani wrote:
Yes, you are right. Copying the ustring to a std::string gets rid of the error but still doesn't work right because it is interpreted as ASCII in the console.
std::cout does not understand UTF-8. That's why glibmm tries to do a
conversion (with the Glib::convert_*() functions. That's documented by
the way:
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1ustring.html#_details

But I don't know why the conversion is failing in your case. Maybe it's
a problem with the glib installation on windows.
Isn't the whole point of UTF-8 that std::cout doesn't need to understand it?

Shouldn't it be the console (or whatever is reading the output) who tries to understand it?

No, I don't think that's how it works, though I guess that would be
nice. I'm quite sure that something in C++ standard streams assumes that
one character is one byte.

Probably.

It's a pity that C++ _still_ doesn't have UTF-8 support in its standard,
or apparently any sign that it will get into the standard any time soon.

Well, C++ is getting two new types. char16_t and char32_t (or something like that) whose intended purpose is to support utf-16 and utf-32.

But yes, I need to figure out why the conversion is failing in the first place rather than trying these hacks (ustring -> std::string).

--
Sohail Somani
http://uint32t.blogspot.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]