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
しかし、 andの同様のオーバーロードはないようですconst wchar_t*
。
ソースコードに追加すると、送信が機能CStringW
するoperator<<
ようです(私の個人的な好み: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