A sequential collection of UTF-16 Unicode characters representing a text string. For more examples and info about winrt::hstring, see String handling in C++/WinRT.
The winrt::hstring type encapsulates HSTRING behind an interface similar to that of std::wstring. A HSTRING is a handle to a Windows Runtime string. For info about how to set an HSTRING into a winrt::hstring, and how to retrieve an HSTRING from a winrt::hstring, see Interoperating with the ABI's HSTRING.
Syntaxstruct hstring
Requirements
Minimum supported SDK: Windows SDK version 10.0.17134.0 (Windows 10, version 1803)
Namespace: winrt
Header: %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (included by default)
Member type aliases Alias name Type hstring::value_type A synonym for wchar_t. hstring::size_type A synonym for uint32_t. hstring::const_reference A synonym for hstring::value_type const&. hstring::const_pointer A synonym for hstring::value_type const*. hstring::const_iterator A synonym for hstring::const_pointer. hstring::const_reverse_iterator A synonym for std::reverse_iterator<hstring::const_iterator>. Constructors Member functions Member operators Free functions Function Description attach_abi function Attaches a hstring object to a handle to a Windows Runtime string. copy_from_abi function Copies to a hstring object from a handle to a Windows Runtime string. Clears the hstring, copies the parameter, and begins managing the handle. copy_to_abi function Copies to a handle to a Windows Runtime string from a hstring object. detach_abi function Detaches a hstring object from its handle, perhaps to return it to a caller. to_hstring function Converts an input value to a winrt::hstring containing the value's string representation. Free operators IteratorsAn hstring is a range, and that range is defined by the hstring::begin and hstring::end member functions, each of which returns a const iterator (as do hstring::cbegin and hstring::cend). Because of this, you can enumerate the characters in an hstring object with either a range-based for
statement, or with the std::for_each template function.
#include <iostream>
using namespace winrt;
...
void Iterators(hstring const& theHstring)
{
for (auto const& element : theHstring)
{
std::wcout << element;
}
std::for_each(theHstring.cbegin(), theHstring.cend(), [](T const& element) { std::wcout << element; });
}
hstring::hstring constructor
Initializes a new instance of the hstring struct with a copy of the input string data.
Syntaxhstring() noexcept;
hstring(winrt::hstring const& h);
explicit hstring(std::wstring_view const& v);
hstring(wchar_t const* c);
hstring(wchar_t const* c, uint32_t s);
Parameters
h
An hstring value that initializes the hstring object.
v
A std::wstring_view value that initializes the hstring object.
c
A pointer to an array of constant wchar_t that initializes the hstring object.
s
A number that specifies a fixed size for the hstring object.
using namespace winrt;
...
void Constructors(
hstring const& theHstring,
std::wstring_view const& theWstringView,
wchar_t const* wideLiteral,
std::wstring const& wideString)
{
// hstring() noexcept
hstring fromDefault{};
// hstring(hstring const& h)
hstring fromHstring{ theHstring };
// explicit hstring(std::wstring_view const& value)
hstring fromWstringView{ theWstringView };
// hstring(wchar_t const* value)
hstring fromWideLiteral{ wideLiteral };
hstring fromWideString{ wideString.c_str() };
// hstring(wchar_t const* value, uint32_t size)
hstring fromWideLiteralWithSize{ wideLiteral, 256 };
hstring fromWideStringWithSize{ wideString.c_str(), 256 };
}
hstring::back function
Returns a reference to the last character in the hstring object.
Syntaxwchar_t const& back() const noexcept;
Return value
A reference to the last character in the hstring object.
hstring::begin functionReturns a const iterator to the first character in the hstring object. See Iterators.
Syntaxwchar_t const* begin() const noexcept;
Return value
A const iterator to the first character in the hstring object.
hstring::c_str functionReturns a pointer to the underlying null-terminated C-style string of the characters in the hstring object; no copy is made.
Syntaxwchar_t const* c_str() const noexcept;
Return value
A pointer to the underlying null-terminated C-style string of the characters in the hstring object; no copy is made.
Example#include <iostream>
using namespace winrt;
...
void PrintHstring(hstring const& theHstring)
{
// You can get a standard wide string from an hstring.
std::wcout << theHstring.c_str() << std::endl;
}
hstring::cbegin function
Returns a const iterator to the first character in the hstring object. See Iterators.
Syntaxwchar_t const* cbegin() const noexcept;
Return value
A const iterator to the first character in the hstring object.
hstring::cend functionReturns a const iterator to one beyond the end of (one beyond the last character in) the hstring object. See Iterators.
Syntaxwchar_t const* cend() const noexcept;
Return value
A const iterator to one beyond the end of (one beyond the last character in) the hstring object.
hstring::clear functionMakes the hstring object empty.
Syntaxvoid clear() noexcept;
hstring::crbegin function
Returns a const reverse iterator to one beyond the end of (one beyond the last character in) the hstring object.
Syntaxstd::reverse_iterator<wchar_t const*> crbegin() const noexcept;
Return value
A const reverse iterator to one beyond the end of (one beyond the last character in) the hstring object.
hstring::crend functionReturns a const reverse iterator to the first character in the hstring object.
Syntaxstd::reverse_iterator<wchar_t const*> crend() const noexcept;
Return value
A const reverse iterator to the first character in the hstring object.
hstring::data functionReturns a null-terminated C-style string version of the characters in the hstring object.
Syntaxwchar_t const* data() const noexcept;
Return value
A null-terminated C-style string version of the characters in the hstring object.
Example#include <iostream>
using namespace winrt;
...
void PrintHstring(hstring const& theHstring)
{
// You can get a standard wide string from an hstring.
std::wcout << theHstring.data() << std::endl;
}
hstring::empty function
Returns a value indicating whether the hstring object is empty.
Syntaxbool empty() const noexcept;
Return value
true
if the hstring object is empty, otherwise false
.
Returns a const iterator to one beyond the end of (one beyond the last character in) the hstring object. See Iterators.
Syntaxwchar_t const* end() const noexcept;
Return value
A const iterator to one beyond the end of (one beyond the last character in) the hstring object.
hstring::front functionReturns a reference to the first character in the hstring object.
Syntaxwchar_t const& front() const noexcept;
Return value
A reference to the first character in the hstring object.
hstring::operator std::wstring_viewConverts the hstring object to a std::wstring_view.
Syntaxoperator std::wstring_view() const noexcept;
Return value
The hstring object converted to a std::wstring_view.
Exampleusing namespace winrt;
...
Uri contosoUri{ L"https://www.contoso.com" };
Uri awUri{ L"https://www.adventure-works.com" };
// Uri::Domain() is of type hstring. But we can use hstring's conversion operator to std::wstring_view.
std::wstring domainWstring{ contosoUri.Domain() }; // L"contoso.com"
domainWstring = awUri.Domain(); // L"https://www.adventure-works.com"
hstring::operator[] (subscript operator)
Returns a reference to the character at the specified position within the hstring object.
Syntaxwchar_t const& operator[](uint32_t pos) const noexcept;
Parameters
pos
A zero-based character position, or index.
A reference to the character at the specified position within the hstring object.
hstring::operator= (assignment operator)Assigns a value to the hstring object.
Syntaxwinrt::hstring& operator=(winrt::hstring const& h);
winrt::hstring& operator=(std::wstring_view const& v);
Parameters
h
An hstring value to assign to the hstring object.
v
A std::wstring_view value to assign to the hstring object.
A reference to the hstring object.
hstring::rbegin functionReturns a const reverse iterator to one beyond the end of (one beyond the last character in) the hstring object.
Syntaxstd::reverse_iterator<wchar_t const*> rbegin() const noexcept;
Return value
A const reverse iterator to one beyond the end of (one beyond the last character in) the hstring object.
hstring::rend functionReturns a const reverse iterator to the first character in the hstring object.
Syntaxstd::reverse_iterator<wchar_t const*> rend() const noexcept;
Return value
A const reverse iterator to the first character in the hstring object.
hstring::size functionReturns the number of characters in the hstring object.
Syntaxuint32_t size() const noexcept;
Return value
A uint32_t containing the number of characters in the hstring object.
attach_abi functionAttaches a hstring object to a handle to a Windows Runtime string.
Syntaxvoid attach_abi(winrt::hstring& object, HSTRING value) noexcept;
Parameters
object
A hstring object to operate on.
value
A handle to a Windows Runtime string.
Copies to a hstring object from a handle to a Windows Runtime string. Clears the hstring, copies the parameter, and begins managing the handle.
Syntaxvoid copy_from_abi(winrt::hstring& object, HSTRING value);
Parameters
object
A hstring object to operate on.
value
A handle to a Windows Runtime string.
Copies to a handle to a Windows Runtime string from a hstring object.
Syntaxvoid copy_to_abi(winrt::hstring const& object, HSTRING& value);
Parameters
object
A hstring object to operate on.
value
A handle reference, via which to copy the hstring's handle.
Detaches a hstring object from its handle, perhaps to return it to a caller.
SyntaxHSTRING detach_abi(winrt::hstring& object) noexcept;
HSTRING detach_abi(winrt::hstring&& object) noexcept;
Parameters
object
A hstring object to operate on.
The handle to the Windows Runtime string.
operator!= (inequality operator)Returns a value indicating whether the two parameters are unequal to one another.
Syntaxinline bool operator!=(winrt::hstring const& hLeft, winrt::hstring const& hRight) noexcept;
inline bool operator!=(winrt::hstring const& hLeft, std::wstring const& wRight) noexcept;
inline bool operator!=(winrt::hstring const& hLeft, wchar_t const* cRight) noexcept;
inline bool operator!=(std::wstring const& wLeft, winrt::hstring const& hRight) noexcept;
inline bool operator!=(wchar_t const* cLeft, winrt::hstring const& hRight) noexcept;
Parameters
hLeft
hRight
An hstring value to compare with the other parameter.
wLeft
wRight
A std::wstring
value to compare with the other parameter.
cLeft
cRight
A pointer to an array of constant wchar_t to compare with the other parameter.
true
if the two parameters are unequal to one another, otherwise false
.
Returns a new hstring object resulting from concatenating the two parameters together.
Syntaxinline hstring operator+(winrt::hstring const& hLeft, winrt::hstring const& hRight);
inline hstring operator+(winrt::hstring const& hLeft, std::wstring const& wRight);
inline hstring operator+(winrt::hstring const& hLeft, std::wstring_view const& vRight);
inline hstring operator+(winrt::hstring const& hLeft, wchar_t const* cRight);
inline hstring operator+(winrt::hstring const& hLeft, wchar_t scRight);
inline hstring operator+(std::wstring const& wLeft, winrt::hstring const& hRight);
inline hstring operator+(std::wstring_view const& vLeft, winrt::hstring const& hRight);
inline hstring operator+(wchar_t const* cLeft, winrt::hstring const& hRight);
inline hstring operator+(wchar_t scLeft, winrt::hstring const& hRight);
Parameters
hLeft
hRight
An hstring value to concatenate with the other parameter.
wLeft
wRight
A std::wstring
value to concatenate with the other parameter.
vLeft
vRight
A std::wstring_view value to concatenate with the other parameter.
cLeft
cRight
A pointer to an array of constant wchar_t to concatenate with the other parameter.
scLeft
scRight
A wchar_t to concatenate with the other parameter.
A new hstring object resulting from concatenating the two parameters together.
operator< (less-than operator)Returns a value indicating whether the first parameter is less than the second parameter.
Syntaxinline bool operator<(winrt::hstring const& hLeft, winrt::hstring const& hRight) noexcept;
inline bool operator<(winrt::hstring const& hLeft, std::wstring const& wRight) noexcept;
inline bool operator<(winrt::hstring const& hLeft, wchar_t const* cRight) noexcept;
inline bool operator<(std::wstring const& wLeft, winrt::hstring const& hRight) noexcept;
inline bool operator<(wchar_t const* cLeft, winrt::hstring const& hRight) noexcept;
Parameters
hLeft
hRight
An hstring value to compare with the other parameter.
wLeft
wRight
A std::wstring
value to compare with the other parameter.
cLeft
cRight
A pointer to an array of constant wchar_t to compare with the other parameter.
true
if the first parameter is less than the second parameter, otherwise false
.
Returns a value indicating whether the first parameter is less than or equal to the second parameter.
Syntaxinline bool operator<=(winrt::hstring const& hLeft, winrt::hstring const& hRight) noexcept;
inline bool operator<=(winrt::hstring const& hLeft, std::wstring const& wRight) noexcept;
inline bool operator<=(winrt::hstring const& hLeft, wchar_t const* cRight) noexcept;
inline bool operator<=(std::wstring const& wLeft, winrt::hstring const& hRight) noexcept;
inline bool operator<=(wchar_t const* cLeft, winrt::hstring const& hRight) noexcept;
Parameters
hLeft
hRight
An hstring value to compare with the other parameter.
wLeft
wRight
A std::wstring
value to compare with the other parameter.
cLeft
cRight
A pointer to an array of constant wchar_t to compare with the other parameter.
true
if the first parameter is less than or equal to the second parameter, otherwise false
.
Returns a value indicating whether the two parameters are equal to one another.
Syntaxinline bool operator==(winrt::hstring const& hLeft, winrt::hstring const& hRight) noexcept;
inline bool operator==(winrt::hstring const& hLeft, std::wstring const& wRight) noexcept;
inline bool operator==(winrt::hstring const& hLeft, wchar_t const* cRight) noexcept;
inline bool operator==(std::wstring const& wLeft, winrt::hstring const& hRight) noexcept;
inline bool operator==(wchar_t const* cLeft, winrt::hstring const& hRight) noexcept;
Parameters
hLeft
hRight
An hstring value to compare with the other parameter.
wLeft
wRight
A std::wstring
value to compare with the other parameter.
cLeft
cRight
A pointer to an array of constant wchar_t to compare with the other parameter.
true
if the two parameters are equal to one another, otherwise false
.
Returns a value indicating whether the first parameter is greater than the second parameter.
Syntaxinline bool operator>(winrt::hstring const& hLeft, winrt::hstring const& hRight) noexcept;
inline bool operator>(winrt::hstring const& hLeft, std::wstring const& wRight) noexcept;
inline bool operator>(winrt::hstring const& hLeft, wchar_t const* cRight) noexcept;
inline bool operator>(std::wstring const& wLeft, winrt::hstring const& hRight) noexcept;
inline bool operator>(wchar_t const* cLeft, winrt::hstring const& hRight) noexcept;
Parameters
hLeft
hRight
An hstring value to compare with the other parameter.
wLeft
wRight
A std::wstring
value to compare with the other parameter.
cLeft
cRight
A pointer to an array of constant wchar_t to compare with the other parameter.
true
if the first parameter is greater than the second parameter, otherwise false
.
Returns a value indicating whether the first parameter is greater than or equal to the second parameter.
Syntaxinline bool operator>=(winrt::hstring const& hLeft, winrt::hstring const& hRight) noexcept;
inline bool operator>=(winrt::hstring const& hLeft, std::wstring const& wRight) noexcept;
inline bool operator>=(winrt::hstring const& hLeft, wchar_t const* cRight) noexcept;
inline bool operator>=(std::wstring const& wLeft, winrt::hstring const& hRight) noexcept;
inline bool operator>=(wchar_t const* cLeft, winrt::hstring const& hRight) noexcept;
Parameters
hLeft
hRight
An hstring value to compare with the other parameter.
wLeft
wRight
A std::wstring
value to compare with the other parameter.
cLeft
cRight
A pointer to an array of constant wchar_t to compare with the other parameter.
true
if the first parameter is greater than or equal to the second parameter, otherwise false
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4