std::operator<<,>>
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody>| Elemento definito nell'header <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)
In primo luogo, costruisce un oggetto std::basic_ostream::sentry, che svuota il legame () 'd flusso, se necessario, e verifica errori. Se l'oggetto sentinella restituisce
false, esce immediatamente.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.
Successivamente, se la sentinella oggetto
true rendimenti, determina il formato di uscita imbottitura nella stessa maniera della fase 3 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.
Poi memorizza ogni carattere della sequenza risultante (il contenuto di
str più imbottitura) nel flusso di output os come se chiamando os.rdbuf()->sputn(seq, n), dove 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.
Infine, chiede
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)
In primo luogo, costruisce un oggetto std::basic_istream::sentry, che svuota il legame () 'd flusso se necessario, estratti ed elimina tutti i caratteri principali di spazio bianco a meno che la bandiera
ios_base::skipws è stato cancellato, e controlli per gli errori. Se l'oggetto sentinella restituisce false, esce immediatamente.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.
In seguito, se i rendimenti sentinella oggetto
true, cancella str con 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.
Poi legge i caratteri da
is e li aggiunge al str come per str.append(1, c), fino a quando una delle seguenti condizioni diventa vero: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.
Ncaratteri vengono letti, doveNèis.width()seis.width() > 0, altrimentiNèstr.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 fine del file condizione si verifica nel
isflussoOriginal: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())è vero per il carattere successivocinis(questo carattere di spaziatura rimane nel flusso di input).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.
Se nessun carattere vengono estratti poi
std::ios::failbit è impostato su is, che possono gettare 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.
Infine, chiama
os.width(0) e distrugge l'oggetto 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.
Eccezioni
1)
potrebbe generare std::ios_base::failure se viene generata un'eccezione durante l'output.
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)
può gettare std::ios_base::failure se non i caratteri vengono estratti dal
is (ad esempio, il flusso è alla fine del file, o è costituito da spazi bianchi solo), o se viene generata un'eccezione durante l'ingresso.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.
Parametri
| os | - | un flusso di output di caratteri
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 flusso di immissione dei caratteri
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 stringa da inserire o estrarre
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. |
Valore di ritorno
1) os
2) is
Esempio
#include <iostream>
#include <string>
int main()
{
std::string greeting = "Hello, whirled!"
std::cout << greeting << '\n';
}
Output:
Hello, whirled!