考虑到 VS2010 SP1,我发现在<ostream>
标头中存在std::ostringstream
and的重载const char*
:
template<class _Traits> inline
basic_ostream<char, _Traits>& operator<<(
basic_ostream<char, _Traits>& _Ostr,
const char *_Val)
{ // insert NTBS into char stream
...
std::wostringstream
但是和似乎没有类似的重载const wchar_t*
。
如果将其添加到源代码中,发送CStringW
withoperator<<
似乎可以工作(我个人的偏好:使用CString::GetString()
字符串流的方法和operator<<
):
namespace std {
template<class _Traits> inline
basic_ostream<wchar_t, _Traits>& operator<<(
basic_ostream<wchar_t, _Traits>& _Ostr,
const wchar_t *_Val)
{
ATLTRACE("It's me, the new overload!\n");
typedef wchar_t _Elem;
//
// *** Copy and paste *** the source code from the following overload:
//
// template<class _Elem,
// class _Traits> inline
// basic_ostream<_Elem, _Traits>& operator<<(
// basic_ostream<_Elem, _Traits>& _Ostr, const _Elem *_Val)
//
//
// NOTE: I don't want to infringe any copyright.
//
// Moderators please delete the following lines if they
// infringe any copyright.
//
typedef basic_ostream<_Elem, _Traits> _Myos;
ios_base::iostate _State = ios_base::goodbit;
streamsize _Count = (streamsize)_Traits::length(_Val); // may overflow
streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() <= _Count
? 0 : _Ostr.width() - _Count;
const typename _Myos::sentry _Ok(_Ostr);
if (!_Ok)
_State |= ios_base::badbit;
else
{ // state okay, insert
_TRY_IO_BEGIN
if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left)
for (; 0 < _Pad; --_Pad) // pad on left
if (_Traits::eq_int_type(_Traits::eof(),
_Ostr.rdbuf()->sputc(_Ostr.fill())))
{ // insertion failed, quit
_State |= ios_base::badbit;
break;
}
if (_State == ios_base::goodbit
&& _Ostr.rdbuf()->sputn(_Val, _Count) != _Count)
_State |= ios_base::badbit;
if (_State == ios_base::goodbit)
for (; 0 < _Pad; --_Pad) // pad on right
if (_Traits::eq_int_type(_Traits::eof(),
_Ostr.rdbuf()->sputc(_Ostr.fill())))
{ // insertion failed, quit
_State |= ios_base::badbit;
break;
}
_Ostr.width(0);
_CATCH_IO_(_Ostr)
}
_Ostr.setstate(_State);
return (_Ostr);
}
} // namespace std