Subject: Re: [Boost-bugs] [Boost C++ Libraries] #7929: boost::lexical_cast< std::string, std::wstring > gives a compiler error.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-06-12 19:07:09
#7929: boost::lexical_cast< std::string, std::wstring > gives a compiler error.
-------------------------------+-----------------------------
Reporter: nate@⦠| Owner: vladimir_prus
Type: Bugs | Status: new
Milestone: To Be Determined | Component: program_options
Version: Boost 1.52.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+-----------------------------
Comment (by nate@â¦):
Perhaps one can look to the standard library for inspiration? In the
`locale` header there is the
[http://en.cppreference.com/w/cpp/locale/codecvt std::codecvt] class which
can be used with [http://en.cppreference.com/w/cpp/locale/wstring_convert
std::wstring_convert] to perform convertions from one encoding to another.
Below is an example using the C++11 class
[http://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16
std::codecvt_utf8_utf16] to convert a UTF-16 `std::wstring` to a UTF-8
encoded `std::string`. I am using this in my application to great success
so far.
{{{
std::wstring wideString;
std::wstring_convert<
std::codecvt_utf8_utf16< std::wstring::value_type >,
std::wstring::value_type
> utf16conv;
std::string narrowString = utf16conv.to_bytes( wideString );
}}}
I hope this helps to show a potential way to narrow characters.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7929#comment:4> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC