std::operator<<,>>
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody>| Déclaré dans l'en-tête <string>
|
||
template <class CharT, class Traits, class Allocator> std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const std::basic_string<CharT, Traits, Allocator>& str); |
(1) | |
template <class CharT, class Traits, class Allocator> std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, std::basic_string<CharT, Traits, Allocator>& str); |
(2) | |
1)
Tout d'abord, construit un objet std::basic_ostream::sentry, qui évacue la cravate () 'd flux si nécessaire et vérifie les erreurs. Si l'objet sentinelle retourne
false, quitte immédiatement .Original:
First, constructs a std::basic_ostream::sentry object, which flushes the tie()'d stream if necessary and checks for errors. If the sentry object returns
false, exits immediately.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ensuite, si l'objet
true retours sentinelle, détermine le rembourrage format de sortie de la même manière que l'étape 3 de num_put::put() . Original:
Afterwards, if the sentry object returns
true, determines the output format padding in the same manner as stage 3 of num_put::put(). The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Puis stocke chaque caractère de la séquence résultante (le contenu de
str ainsi padding) pour le flux de sortie os comme si en appelant os.rdbuf()->sputn(seq, n), où n=std::max(os.width(), str.size())Original:
Then stores each character from the resulting sequence (the contents of
str plus padding) to the output stream os as if by calling os.rdbuf()->sputn(seq, n), where n=std::max(os.width(), str.size())The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Enfin, les appels
os.width(0) .Original:
Finally, calls
os.width(0).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
Tout d'abord, construit un objet std::basic_istream::sentry, qui évacue la cravate () 'd flux si nécessaire, des extraits et des rejets tous les personnages principaux espaces blancs à moins que le drapeau
ios_base::skipws a été défrichées, et vérifie les erreurs. Si l'objet sentinelle retourne false, quitte immédiatement .Original:
First, constructs a std::basic_istream::sentry object, which flushes the tie()'d stream if necessary, extracts and discards all leading whitespace characters unless the
ios_base::skipws flag was cleared, and checks for errors. If the sentry object returns false, exits immediately.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ensuite, si les rendements objet sentinelle
true, efface str avec str.erase()Original:
Afterwards, if the sentry object returns
true, clears str with str.erase()The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Puis lit les caractères à partir de
is et les ajoute à str comme par str.append(1, c), jusqu'à ce que l'une des conditions suivantes est remplie:Original:
Then reads characters from
is and appends them to str as if by str.append(1, c), until one of the following conditions becomes true:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ncaractères sont lus, oùNestis.width()siis.width() > 0, sinonNeststr.max_size()Original:Ncharacters are read, whereNisis.width()ifis.width() > 0, otherwiseNisstr.max_size()The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.- la condition de fin de fichier se produit dans le courant de
isOriginal:the end-of-file condition occurs in the streamisThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. std::isspace(c,is.getloc())est vrai pour le caractère suivant danscis(ce caractère d'espacement reste dans le flux d'entrée) .Original:std::isspace(c,is.getloc())is true for the next charactercinis(this whitespace character remains in the input stream).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si aucun caractère n'est extraite puis
std::ios::failbit est réglé sur is, ce qui peut jeter std::ios_base::failure .Original:
If no characters are extracted then
std::ios::failbit is set on is, which may throw std::ios_base::failure.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Enfin, les appels
os.width(0) et détruit l'objet std::basic_istream::sentry . Original:
Finally, calls
os.width(0) and destroys the std::basic_istream::sentry object. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Exceptions
1)
peut jeter std::ios_base::failure si une exception est levée lors de la sortie .
Original:
may throw std::ios_base::failure if an exception is thrown during output.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
peut jeter std::ios_base::failure si aucun caractère sont extraites de
is (par exemple, le flux est à la fin du fichier, ou est constitué d'espaces uniquement), ou si une exception est levée lors de l'entrée .Original:
may throw std::ios_base::failure if no characters are extracted from
is (e.g the stream is at end of file, or consists of whitespace only), or if an exception is thrown during input.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Paramètres
| os | - | un flux de sortie de caractères
Original: a character output stream The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| is | - | un flux d'entrée de caractères
Original: a character input stream The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| str | - | la chaîne à insérer ou à extraire
Original: the string to be inserted or extracted The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Retourne la valeur
1) os
2) is
Exemple
#include <iostream>
#include <string>
int main()
{
std::string greeting = "Hello, whirled!"
std::cout << greeting << '\n';
}
Résultat :
Hello, whirled!