[MS] The Windows Runtime winrt::hstring and the C++ std::wstring are inter-assignable - devamazonaws.blogspot.com

For the past few days, I've been talking about converting between various string types while avoiding data loss and security issues if an embedded null is present. But in the case where you are dealing with winrt::hstring and std::wstring, the story is much simpler.

The winrt::hstring and std::wstring types can simply be assigned to each other. No need to do funny wstring_view or c_str() nonsense.

winrt::hstring h;
std::wstring s;

h = s; // this works!
s = h; // this also works!

The assignments work because winrt::hstring and std::wstring both support assignment from std::wstring_view, and both winrt::hstring and std::wstring are convertible to std::wstring_view.


Post Updated on June 21, 2024 at 03:00PM
Thanks for reading
from devamazonaws.blogspot.com

Comments

Popular posts from this blog

[MS] Pulling a single item from a C++ parameter pack by its index, remarks - devamazonaws.blogspot.com

[MS] Debugger breakpoints are usually implemented by patching the in-memory copy of the code - devamazonaws.blogspot.com

[MS] The case of the crash when destructing a std::map - devamazonaws.blogspot.com