Hi All,
I've done a little homework (I've read responses to similar from P.J.
Plauger and Dietmar Kuehl), and wanted to verify with the Group. Below
is what I am performing (Stroustrup's Appendix D recommendation won't
compile in Microsoft VC++ 6.0).
My question is in reference to MultiByte Character Sets. Will this code
perform as expected? I understand every problem has a simple and
elegant solution that is wrong.
I generally use US English or Unicode, so I don't encounter a lot of
issues others may see (a multibyte character using std::string). I have
verified it works with a Hello World sample.
Jeff
Jeffrey Walton
std::string s = "Hello World";
std::ctype<wchar_tct;
std::wstring ws;
for( std::string::const_iterator it = s.begin(); it != s.end();
it++ )
{
ws += ct.widen( *it );
}
// http://www.research.att.com/~bs/3rd_loc.pdf
// by Bjourne himself...
// page 28 of the above reference
// or
// The C++ Programming Language, Special Edition
// Section D.4.2.2, p 895 (Full Manual)
//
// const std::locale& loc = s.getloc();
// wchar_t w = std::use_facet< std::ctype<char(loc).widen(c);
// does not compile in Microsft's environment...
// getloc() is not a member of std::basic_string< ... ...
//
// Dietmar Kuehl code
// Does not compile in VC++ 6.0
//
// std::wstring to_wide_string(std::string const& source) {
// typedef std::ctype<wchar_tCT;
// std::wstring rc;
// rc.resize(source.size());
// CT const& ct = std::use_facet<CT>(std::locale());
// ct.widen(source.data(), source.data() + source.size(),
rc.data());
// return rc;