I assume that wchar_std::wstring is a typo and should be just std::wstring
Other than that I guess that m_player->health is a std::string rather than a std::wstring.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm building the UI for the health
//New -----------------------
const wchar_std::wstring output = std::wstring(L"Player-Health:") + std::wstring(m_player->health);
This std::wstring(m_player->health) has this error:
Error (active) E0289 no instance of constructor "std::basic_string<_Elem, _Traits, _Alloc>::basic_string [with _Elem=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]" matches the argument list "
I assume that wchar_std::wstring is a typo and should be just std::wstring
Other than that I guess that m_player->health is a std::string rather than a std::wstring.
Hi,
You could use to_wstring
const std::wstring output = std::wstring(L"Player-Health:") + std::to_wstring(m_player->health);
Best regards,
Minxin Yu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
The following part of the error message: "std::basic_string<_Elem, _Traits, _Alloc>::basic_string [with _Elem=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]"
is basically a very verbose way to identify std::wstring
. It's kind of "std::wstring
as seen from the C++ compiler's glasses".
In simple terms, the C++ compiler with that error message is basically telling you that it can't find a proper std::wstring constructor to build a std::wstring
instance from the m_player->health
.
So, the question now is: What is the type of m_player->health
?
If it's a numeric value like an int
, or float
, or double
, etc. you may simply invoke std::to_wstring to convert it to a std::wstring
instance.
If it's an instance of std::string
, you should clarify what encoding is used to represent the text, and properly convert from that encoding to Unicode UTF-16 to store the text in std::wstring
. To do that, you can invoke the MultiByteToWideChar
API, or reuse some available open-source Unicode conversion code.