While searching for any kind of function in could help printing data to debug console, I've found this function here on StackOverflow
that can print almost any kind of data:
template <typename Arg, typename... Args>
void doPrint(Arg&& arg, Args&&... args)
{
std::stringstream out;
out << std::forward<Arg>(arg);
using expander = int[];
(void)expander {
0, (void(out << std::left << std::setw(20) << std::forward<Args>(args)), 0)...
};
OutputDebugStringA(out.str().c_str());
}
But it doesn't work when I try to pass a wstring
to it, ex:
std::wstring color = L"blue";
doPrint("color: ", color);
I get this error:
Error C2679 binary '<<': no operator found which takes a right-hand operand of type 'std::wstring' (or there is no acceptable conversion)
Is it possible to also support wstring
?
I tried to change std::stringstream
to std::wstringstream
, but now I get error on OutputDebugStringA()
:
void OutputDebugStringA(LPCSTR)': cannot convert argument 1 from 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>' to 'LPCSTR'