<ostream>
, opérateurs
operator<<
Écrit différents types dans le flux.
template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
basic_ostream<_Elem, _Tr>& _Ostr,
const Elem* str);
template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
basic_ostream<_Elem, _Tr>& _Ostr,
Elem _Ch);
template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
basic_ostream<_Elem, _Tr>& _Ostr,
const char* str);
template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
basic_ostream<_Elem, _Tr>& _Ostr,
char _Ch);
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
const char* str);
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _ostr,
char _Ch);
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
const signed char* str);
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
signed char _Ch);
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
const unsigned char* str);
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
unsigned char _Ch);
template <class _Elem, class _Tr, class T>
basic_ostream <_Elem, _Tr>& operator<<(
basic_ostream<_Elem, _Tr>&& _Ostr,
Ty val);
Paramètres
_Ch
Un caractère.
_Elem
Type de l’élément.
_Ostr
Objet basic_ostream
.
str
Chaîne caractère.
_Tr
Caractéristiques de caractère.
val
Le type
Valeur de retour
Flux.
Notes
La classe basic_ostream
définit également plusieurs opérateurs d’insertion. Pour plus d’informations, consultez basic_ostream::operator<<
.
La fonction de modèle
template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
basic_ostream<Elem, _Tr>& _ostr,
const Elem *str);
détermine la longueur N = traits_type::
length(str
) de la séquence commençant à str et insère la séquence. Si la largeur N<_Ostr.
, la fonction insère également une répétition de caractères de _Ostr.width
remplissage N. La répétition précède la séquence si (_Ostr
. flags & adjustfield
!= left. Sinon, la répétition suit la séquence. La fonction retourne _Ostr.
La fonction de modèle
template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
basic_ostream<Elem, _Tr>& _Ostr,
Elem _Ch);
insère l’élément _Ch
. Si 1 <_Ostr.width
, la fonction insère également une répétition de - _Ostr.width
1 caractères de remplissage. La répétition précède la séquence si _Ostr.flags & adjustfield != left
. Sinon, la répétition suit la séquence. Elle retourne _Ostr.
La fonction de modèle
template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
basic_ostream<Elem, _Tr>& _Ostr,
const char *str);
se comporte comme
template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
basic_ostream<Elem, _Tr>& _Ostr,
const Elem *str);
sauf que chaque élément _Ch de la séquence commençant à str est converti en objet de type Elem
en appelant_Ostr.
put(_Ostr.
widen(_Ch
)).
La fonction de modèle
template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
basic_ostream<Elem, _Tr>& _Ostr,
char _Ch);
se comporte comme
template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
basic_ostream<Elem, _Tr>& _Ostr,
Elem _Ch);
sauf que _Ch est converti en objet de type Elem
en appelant _Ostr.put( _Ostr.widen( _Ch ))
.
La fonction de modèle
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
const char *str);
se comporte comme
template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
basic_ostream<Elem, _Tr>& _Ostr,
const Elem *str);
(Elle n’a pas besoin d’élargir les éléments avant de les insérer.)
La fonction de modèle
template <class _Tr>
basic_ostream<char, Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
char _Ch);
se comporte comme
template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
basic_ostream<Elem, _Tr>& _Ostr,
Elem _Ch);
(Il n’est pas obligé d’élargir _Ch avant de l’insérer.)
La fonction de modèle
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
const signed char *str);
Retourne _Ostr << (const char *)str
.
La fonction de modèle
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
signed char _Ch);
Retourne _Ostr << (char)_Ch
.
La fonction de modèle
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
const unsigned char *str);
Retourne _Ostr << (const char *)str
.
La fonction de modèle
template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
basic_ostream<char, _Tr>& _Ostr,
unsigned char _Ch);
Retourne _Ostr << (char)_Ch
.
La fonction de modèle
template <class _Elem, class _Tr, class T>
basic_ostream<_Elem, _Tr>& operator<<(
basic_ostream<char, _Tr>&& _Ostr,
T val);
retourne _Ostr << val
(et convertit une référence RValue à _Ostr
en lvalue dans le processus).
Exemple
Consultez flush pour obtenir un exemple qui utilise operator<<
.
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