winrt::hstring, struct (C++/WinRT)
Collection séquentielle de caractères Unicode UTF-16 représentant une chaîne de texte. Pour plus d’exemples et d’informations sur winrt ::hstring, consultez Gestion des chaînes en C++/WinRT.
Le type winrt ::hstring encapsule HSTRING derrière une interface similaire à celle de std ::wstring. Un HSTRING est un handle pour une chaîne Windows Runtime. Pour plus d’informations sur la définition d’un HSTRING dans un winrt ::hstring et sur la façon de rertrieve un HSTRING à partir d’un winrt ::hstring, consultez Interopérabilité avec le HSTRING d’ABI.
Syntax
struct hstring
Configuration requise
Kit de développement logiciel (SDK) minimum pris en charge : Sdk Windows version 10.0.17134.0 (Windows 10, version 1803)
Espace de noms : winrt
En-tête : %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (inclus par défaut)
Alias de type de membre
Nom d'alias | Type |
---|---|
hstring ::value_type | Synonyme de wchar_t. |
hstring ::size_type | Synonyme de uint32_t. |
hstring ::const_reference | Synonyme de hstring ::value_type const&. |
hstring ::const_pointer | Synonyme de hstring ::value_type const*. |
hstring ::const_iterator | Synonyme de hstring ::const_pointer. |
hstring ::const_reverse_iterator | Synonyme de std ::reverse_iterator<hstring ::const_iterator>. |
Constructeurs
Constructeur | Description |
---|---|
constructeur hstring ::hstring | Initialise une nouvelle instance du struct hstring avec une copie des données de chaîne d’entrée. |
Fonctions Membre
Fonction | Description |
---|---|
hstring ::back, fonction | Retourne une référence au dernier caractère de l’objet hstring . |
hstring ::begin, fonction | Retourne un itérateur const au premier caractère de l’objet hstring . |
hstring ::c_str, fonction | Retourne un pointeur vers la chaîne de style C terminée par null sous-jacente des caractères de l’objet hstring ; aucune copie n’est effectuée. |
hstring ::cbegin, fonction | Retourne un itérateur const au premier caractère de l’objet hstring . |
hstring ::cend, fonction | Retourne un itérateur const à un au-delà de la fin de (un au-delà du dernier caractère dans) de l’objet hstring . |
hstring ::clear, fonction | Rend l’objet hstring vide. |
hstring ::crbegin, fonction | Retourne un itérateur inverse const à un au-delà de la fin (un au-delà du dernier caractère dans) de l’objet hstring . |
hstring ::crend, fonction | Retourne un itérateur inverse const au premier caractère de l’objet hstring . |
hstring ::d ata, fonction | Retourne une version de chaîne de style C terminée par null des caractères de l’objet hstring . |
hstring ::empty, fonction | Retourne une valeur indiquant si l’objet hstring est vide. |
hstring ::end, fonction | Retourne un itérateur const à un au-delà de la fin de (un au-delà du dernier caractère dans) de l’objet hstring . |
hstring ::front, fonction | Retourne une référence au premier caractère de l’objet hstring . |
hstring ::rbegin, fonction | Retourne un itérateur inverse const à un au-delà de la fin (un au-delà du dernier caractère dans) de l’objet hstring . |
hstring ::rend, fonction | Retourne un itérateur inverse const au premier caractère de l’objet hstring . |
fonction hstring ::size | Retourne le nombre de caractères dans l’objet hstring . |
Opérateurs membres
Opérateur | Description |
---|---|
hstring ::operator std ::wstring_view | Convertit l’objet hstring en std ::wstring_view. |
hstring ::operator[] (opérateur indice)) | Retourne une référence au caractère à la position spécifiée dans l’objet hstring . |
hstring ::operator= (opérateur d’affectation) | Affecte une valeur à l’objet hstring . |
Fonctions gratuites
Fonction | Description |
---|---|
attach_abi, fonction | Attache un objet hstring à un handle à une chaîne Windows Runtime. |
copy_from_abi, fonction | Copie dans un objet hstring d’un handle vers une chaîne Windows Runtime. Efface le hstring, copie le paramètre et commence à gérer le handle. |
copy_to_abi, fonction | Copie dans un handle dans une chaîne Windows Runtime à partir d’un objet hstring. |
detach_abi, fonction | Détache un objet hstring de son handle, peut-être pour le retourner à un appelant. |
to_hstring, fonction | Convertit une valeur d’entrée en winrt ::hstring contenant la représentation sous forme de chaîne de la valeur. |
Opérateurs gratuits
Opérateur | Description |
---|---|
operator != (opérateur d’inégalité) | Retourne une valeur indiquant si les deux paramètres sont inégaux l’un à l’autre. |
operator+ (opérateur de concaténation) | Retourne un nouvel objet hstring résultant de la concaténation des deux paramètres ensemble. |
opérateur< (opérateur inférieur à) | Retourne une valeur indiquant si le premier paramètre est inférieur au deuxième paramètre. |
operator<= (opérateur inférieur à ou égal à) | Retourne une valeur indiquant si le premier paramètre est inférieur ou égal au deuxième paramètre. |
operator== (opérateur d’égalité) | Retourne une valeur indiquant si les deux paramètres sont égaux l’un à l’autre. |
opérateur> (supérieur à l’opérateur) | Retourne une valeur indiquant si le premier paramètre est supérieur au deuxième paramètre. |
operator>= (opérateur supérieur à ou égal à) | Retourne une valeur indiquant si le premier paramètre est supérieur ou égal au deuxième paramètre. |
Iterators
Un hstring est une plage, et cette plage est définie par les fonctions membres hstring ::begin et hstring ::end , chacune d’elles retourne un itérateur const (comme le font hstring ::cbegin et hstring ::cend). Pour cette raison, vous pouvez énumérer les caractères d’un objet hstring avec une instruction basée sur for
une plage ou avec la fonction de modèle std ::for_each .
#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, constructeur
Initialise une nouvelle instance du struct hstring avec une copie des données de chaîne d’entrée.
Syntaxe
hstring() 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);
Paramètres
h
Valeur hstring qui initialise l’objet hstring .
v
Valeur std ::wstring_view qui initialise l’objet hstring .
c
Pointeur vers un tableau de constantes wchar_t qui initialise l’objet hstring .
s
Nombre qui spécifie une taille fixe pour l’objet hstring .
Exemple
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, fonction
Retourne une référence au dernier caractère de l’objet hstring .
Syntaxe
wchar_t const& back() const noexcept;
Valeur de retour
Référence au dernier caractère de l’objet hstring .
hstring ::begin, fonction
Retourne un itérateur const au premier caractère de l’objet hstring . Consultez Itérateurs.
Syntaxe
wchar_t const* begin() const noexcept;
Valeur de retour
Itérateur const du premier caractère de l’objet hstring .
fonction hstring ::c_str
Retourne un pointeur vers la chaîne de style C terminée par null sous-jacente des caractères de l’objet hstring ; aucune copie n’est effectuée.
Syntaxe
wchar_t const* c_str() const noexcept;
Valeur de retour
Pointeur vers la chaîne de style C terminée par null sous-jacente des caractères de l’objet hstring ; aucune copie n’est effectuée.
Exemple
#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, fonction
Retourne un itérateur const au premier caractère de l’objet hstring . Consultez Itérateurs.
Syntaxe
wchar_t const* cbegin() const noexcept;
Valeur de retour
Itérateur const du premier caractère de l’objet hstring .
fonction hstring ::cend
Renvoie un itérateur const à un au-delà de la fin de (un au-delà du dernier caractère dans) l’objet hstring . Consultez Itérateurs.
Syntaxe
wchar_t const* cend() const noexcept;
Valeur de retour
Itérateur const à un au-delà de la fin de (un au-delà du dernier caractère dans) l’objet hstring .
fonction hstring ::clear
Rend l’objet hstring vide.
Syntax
void clear() noexcept;
fonction hstring ::crbegin
Retourne un itérateur inverse const à un au-delà de la fin de (un au-delà du dernier caractère dans) de l’objet hstring .
Syntaxe
std::reverse_iterator<wchar_t const*> crbegin() const noexcept;
Valeur de retour
Itérateur inverse const à un au-delà de la fin de (un au-delà du dernier caractère dans) l’objet hstring .
fonction hstring ::crend
Retourne un itérateur inverse const au premier caractère de l’objet hstring .
Syntaxe
std::reverse_iterator<wchar_t const*> crend() const noexcept;
Valeur de retour
Itérateur inverse const du premier caractère de l’objet hstring .
fonction hstring ::d ata
Retourne une version de chaîne de style C terminée par null des caractères de l’objet hstring .
Syntaxe
wchar_t const* data() const noexcept;
Valeur de retour
Version de chaîne de style C terminée par null des caractères de l’objet hstring .
Exemple
#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;
}
fonction hstring ::empty
Retourne une valeur indiquant si l’objet hstring est vide.
Syntaxe
bool empty() const noexcept;
Valeur de retour
true
si l’objet hstring est vide, sinon false
.
fonction hstring ::end
Renvoie un itérateur const à un au-delà de la fin de (un au-delà du dernier caractère dans) l’objet hstring . Consultez Itérateurs.
Syntaxe
wchar_t const* end() const noexcept;
Valeur de retour
Itérateur const à un au-delà de la fin de (un au-delà du dernier caractère dans) l’objet hstring .
hstring ::front, fonction
Renvoie une référence au premier caractère de l’objet hstring .
Syntaxe
wchar_t const& front() const noexcept;
Valeur de retour
Référence au premier caractère de l’objet hstring .
hstring ::operator std ::wstring_view
Convertit l’objet hstring enstd ::wstring_view.
Syntaxe
operator std::wstring_view() const noexcept;
Valeur de retour
Objet hstring converti en std ::wstring_view.
Exemple
using 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[] (opérateur d’indice)
Retourne une référence au caractère à la position spécifiée dans l’objet hstring .
Syntaxe
wchar_t const& operator[](uint32_t pos) const noexcept;
Paramètres
pos
Position de caractère de base zéro ou index.
Valeur retournée
Référence au caractère à la position spécifiée dans l’objet hstring .
hstring ::operator= (opérateur d’affectation)
Affecte une valeur à l’objet hstring .
Syntaxe
winrt::hstring& operator=(winrt::hstring const& h);
winrt::hstring& operator=(std::wstring_view const& v);
Paramètres
h
Valeur hstring à affecter à l’objet hstring .
v
Valeur std ::wstring_view à affecter à l’objet hstring .
Valeur retournée
Référence à l’objet hstring .
hstring ::rbegin, fonction
Retourne un itérateur inverse const à un au-delà de la fin (un au-delà du dernier caractère dans) de l’objet hstring .
Syntaxe
std::reverse_iterator<wchar_t const*> rbegin() const noexcept;
Valeur de retour
Itérateur inverse const à un au-delà de la fin de (un au-delà du dernier caractère dans) de l’objet hstring .
hstring ::rend, fonction
Retourne un itérateur inverse const au premier caractère de l’objet hstring .
Syntaxe
std::reverse_iterator<wchar_t const*> rend() const noexcept;
Valeur de retour
Itérateur inverse const vers le premier caractère de l’objet hstring .
fonction hstring ::size
Retourne le nombre de caractères dans l’objet hstring .
Syntaxe
uint32_t size() const noexcept;
Valeur de retour
Un uint32_t contenant le nombre de caractères dans l’objet hstring.
attach_abi, fonction
Attache un objet hstring à un handle à une chaîne Windows Runtime.
Syntaxe
void attach_abi(winrt::hstring& object, HSTRING value) noexcept;
Paramètres
object
Objet hstring sur lequel opérer.
value
Handle d’une chaîne de Windows Runtime.
copy_from_abi, fonction
Copie dans un objet hstring d’un handle vers une chaîne Windows Runtime. Efface le hstring, copie le paramètre et commence à gérer le handle.
Syntaxe
void copy_from_abi(winrt::hstring& object, HSTRING value);
Paramètres
object
Objet hstring sur lequel opérer.
value
Handle d’une chaîne de Windows Runtime.
copy_to_abi, fonction
Copie dans un handle dans une chaîne Windows Runtime à partir d’un objet hstring.
Syntaxe
void copy_to_abi(winrt::hstring const& object, HSTRING& value);
Paramètres
object
Objet hstring sur lequel opérer.
value
Référence de handle, via laquelle copier le handle du hstring.
detach_abi, fonction
Détache un objet hstring de son handle, peut-être pour le retourner à un appelant.
Syntaxe
HSTRING detach_abi(winrt::hstring& object) noexcept;
HSTRING detach_abi(winrt::hstring&& object) noexcept;
Paramètres
object
Objet hstring sur lequel opérer.
Valeur retournée
Handle de la chaîne Windows Runtime.
operator != (opérateur d’inégalité)
Retourne une valeur indiquant si les deux paramètres sont inégaux l’un à l’autre.
Syntaxe
inline 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;
Paramètres
hLeft
hRight
Valeur hstring à comparer avec l’autre paramètre.
wLeft
wRight
Valeur std::wstring
à comparer avec l’autre paramètre.
cLeft
cRight
Pointeur vers un tableau de constantes wchar_t à comparer avec l’autre paramètre.
Valeur retournée
true
si les deux paramètres sont inégaux l’un à l’autre, sinon false
.
operator+ (opérateur de concaténation)
Retourne un nouvel objet hstring résultant de la concaténation des deux paramètres ensemble.
Syntaxe
inline 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);
Paramètres
hLeft
hRight
Valeur hstring à concaténer avec l’autre paramètre.
wLeft
wRight
Valeur std::wstring
à concaténer avec l’autre paramètre.
vLeft
vRight
Valeur std ::wstring_view à concaténer avec l’autre paramètre.
cLeft
cRight
Pointeur vers un tableau de constantes wchar_t à concaténer avec l’autre paramètre.
scLeft
scRight
Une wchar_t à concaténer avec l’autre paramètre.
Valeur retournée
Nouvel objet hstring résultant de la concaténation des deux paramètres ensemble.
opérateur< (opérateur inférieur à)
Retourne une valeur indiquant si le premier paramètre est inférieur au deuxième paramètre.
Syntaxe
inline 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;
Paramètres
hLeft
hRight
Valeur hstring à comparer avec l’autre paramètre.
wLeft
wRight
Valeur std::wstring
à comparer avec l’autre paramètre.
cLeft
cRight
Pointeur vers un tableau de constantes wchar_t à comparer avec l’autre paramètre.
Valeur retournée
true
si le premier paramètre est inférieur au deuxième paramètre , sinon false
.
operator<= (opérateur inférieur à ou égal à)
Retourne une valeur indiquant si le premier paramètre est inférieur ou égal au deuxième paramètre.
Syntaxe
inline 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;
Paramètres
hLeft
hRight
Valeur hstring à comparer avec l’autre paramètre.
wLeft
wRight
Valeur std::wstring
à comparer avec l’autre paramètre.
cLeft
cRight
Pointeur vers un tableau de constantes wchar_t à comparer avec l’autre paramètre.
Valeur retournée
true
si le premier paramètre est inférieur ou égal au deuxième paramètre , sinon false
.
operator== (opérateur d’égalité)
Retourne une valeur indiquant si les deux paramètres sont égaux l’un à l’autre.
Syntaxe
inline 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;
Paramètres
hLeft
hRight
Valeur hstring à comparer avec l’autre paramètre.
wLeft
wRight
Valeur std::wstring
à comparer avec l’autre paramètre.
cLeft
cRight
Pointeur vers un tableau de constantes wchar_t à comparer avec l’autre paramètre.
Valeur retournée
true
si les deux paramètres sont égaux l’un à l’autre , sinon false
.
opérateur> (opérateur supérieur à)
Retourne une valeur indiquant si le premier paramètre est supérieur au deuxième paramètre.
Syntaxe
inline 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;
Paramètres
hLeft
hRight
Valeur hstring à comparer avec l’autre paramètre.
wLeft
wRight
Valeur std::wstring
à comparer avec l’autre paramètre.
cLeft
cRight
Pointeur vers un tableau de constantes wchar_t à comparer avec l’autre paramètre.
Valeur retournée
true
si le premier paramètre est supérieur au deuxième paramètre , sinon false
.
operator>= (opérateur supérieur à ou égal à)
Retourne une valeur indiquant si le premier paramètre est supérieur ou égal au deuxième paramètre.
Syntaxe
inline 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;
Paramètres
hLeft
hRight
Valeur hstring à comparer avec l’autre paramètre.
wLeft
wRight
Valeur std::wstring
à comparer avec l’autre paramètre.
cLeft
cRight
Pointeur vers un tableau de constantes wchar_t à comparer avec l’autre paramètre.
Valeur retournée
true
si le premier paramètre est supérieur ou égal au deuxième paramètre , sinon false
.
Voir aussi
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour