ostringstream stm;
stm.imbue(loc);
const ctype<char>& ctfacet =
use_facet< ctype<char>>( stm.getloc());
for( size_t i=0; i<str.size(); ++i )
stm << ctfacet.narrow( str[i], 0 );


warning C4244: 'argument' : conversion from 'const wchar_t' to
'std::ctype<char>::_Elem', possible loss of data

Re: How to change code to rid the warning? by Igor

Igor
Sun Jul 20 10:50:29 CDT 2008

"howard" <howard98765@hotmail.com> wrote in message
news:ujHH8Sh6IHA.3684@TK2MSFTNGP05.phx.gbl
> ostringstream stm;
> stm.imbue(loc);
> const ctype<char>& ctfacet =
> use_facet< ctype<char>>( stm.getloc());
> for( size_t i=0; i<str.size(); ++i )
> stm << ctfacet.narrow( str[i], 0 );
>
>
> warning C4244: 'argument' : conversion from 'const wchar_t' to
> 'std::ctype<char>::_Elem', possible loss of data

ctype<T>::narrow takes T and returns char. If you want to narrow from
wchar_t to char, you need to use ctype<wchar_t> facet. I assume, from
the text of the warning, that str is a wstring.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925