$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Sean Rohead (sean.rohead_at_[hidden])
Date: 2005-07-22 19:13:01
I would like to convert between std::wstring and std::string using
lexical_cast and finally discovered in an old posting that you must
manually provide template specializations for these types as below. My
question is why these aren't provided in lexical_cast.hpp already?
template<> inline std::wstring boost::lexical_cast(std::string source)
{
std::wstring result(source.size(), wchar_t(0));
typedef std::ctype<wchar_t> ctype_t;
const ctype_t& ct = std::use_facet<ctype_t>(std::locale());
ct.widen(source.data(), source.data() + source.size(),
&(*result.begin()));
return result;
}
template<> inline std::string boost::lexical_cast(std::wstring source)
{
std::string result(source.size(), char(0));
typedef std::ctype<wchar_t> ctype_t;
const ctype_t& ct = std::use_facet<ctype_t>(std::locale());
ct.narrow(source.data(), source.data() + source.size(), '\u00B6',
&(*result.begin()));
return result;
}