문제

I just noticed that output of a char* through std::wcoutworks totally fine on MSVC (tested with VS2005 and VS 2010).

std::wcout << L"Works as expected";
std::wcout << "This ALSO DOES print the string";

Indeed, debugging into the output we get to the <ostream> header:

template<class _Elem, class _Traits> 
inline basic_ostream<_Elem, _Traits>& 
operator<<(basic_ostream<_Elem, _Traits>& _Ostr, const char *_Val) { ...

However, it would appear that this version is not documented on MSDN nor indeed on cppref (ostream members).

Is this standard? Is this an undocumented MS extension? Does any good come of it?


Do note that the opposite will indeed invokde the void*output:

std::cout << L"Will just print address of string";
도움이 되었습니까?

해결책

At least according to cppref (non-member operator<<) it is defined (see the sixth one down from the top)

template< class CharT, class Traits >
basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, 
                                     const char* s );

Also, looking at the comments:

Before insertion, first, all characters are widened using os.widen(), then ...

this seems well defined by the C++ standard.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top