incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Sebor (JIRA)" <j...@apache.org>
Subject [jira] Updated: (STDCXX-296) std::basic_ostream::operator<<(const wchar_t*)
Date Thu, 05 Oct 2006 21:22:20 GMT
     [ http://issues.apache.org/jira/browse/STDCXX-296?page=all ]

Martin Sebor updated STDCXX-296:
--------------------------------

    Attachment:     (was: ostream.diff)

> std::basic_ostream::operator<<(const wchar_t*)
> ----------------------------------------------
>
>                 Key: STDCXX-296
>                 URL: http://issues.apache.org/jira/browse/STDCXX-296
>             Project: C++ Standard Library
>          Issue Type: New Feature
>          Components: 27. Input/Output
>    Affects Versions: 4.1.2, 4.1.3
>         Environment: all
>            Reporter: Martin Sebor
>
> There is a pair of generic insertion and extraction operators for const char* (i.e.,
that make it possible to insert/extract narrow character strings to/from a stream object specialized
on wchar_t or even user-defined character type), but there are no such operators for wchar_t
(i.e., that would
> make it possible to insert/extract arrays of wchar_t elements to/from narrow streams
or streams specialized on a user-defined character type).
> Such operators would provide a useful and convenient interface to the low-level codecvt
facet, one that could be used to perform in memory
> codeset conversion just as easily and conveniently as fstream performs such conversions
on files. Here's an example of how the insertion
> operator could be used to easily convert from UCS to UTF-8:
> #include <cassert>   // for assert()
> #include <cwchar>    // for mbstate_t
> #include <locale>    // for codecvt, locale
> #include <sstream>   // for ostringstream
> int main ()
> {
>     std::stringstream ostrm;
>     typedef std::codecvt_byname<wchar_t, char, std::mbstate_t> Unicode;
>     ostrm.imbue (std::locale (ostrm.getloc (), new Unicode ("UTF-8@UCS")));
>     // convert the UCS Greek letters alpha, beta, gamma to UTF-8
>     // expected UTF-8 encoding: "\xce\xb1\xce\xb2\xce\xb3"
>     ostrm << L"\x3b1\x3b2\x3b3";
>     assert ("\xce\xb1\xce\xb2\xce\xb3" == ostrm.str ());
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message