[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

Scenarios capability now generally available for Amazon Q in QuickSight - devamazonaws.blogspot.com

[MS] Introducing Pull Request Annotation for CodeQL and Dependency Scanning in GitHub Advanced Security for Azure DevOps - devamazonaws.blogspot.com

AWS Console Mobile Application adds support for Amazon Lightsail - devamazonaws.blogspot.com