std::operator<<,>>
Da cppreference.com
< cpp | string | basic string
![]() | 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. |
Definido no cabeçalho <string> | ||
template<class CharT, class Traits, class Allocator> std::basic_ostream<CharT, Traits>& | (1) | |
template<class CharT, class Traits, class Allocator> std::basic_istream<CharT, Traits>& | (2) | |
Primeiro, constrói um objeto std::basic_ostream::sentry, que libera o empate () 'd fluxo, se necessário, e verifica se há erros. Se o objeto sentinela retorna false, sai imediatamente.
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.
Depois disso, se o objecto de sentinela true retornos, determina o formato de saída de acolchoamento da mesma maneira como o estágio 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.
Em seguida, armazena cada personagem da seqüência resultante (o conteúdo de
str
mais estofo) para o fluxo de saída os
como se chamando os.rdbuf()->sputn(seq, n), onde 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.
Finalmente, chama os.width(0).
2) 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.
Primeiro, constrói um objeto std::basic_istream::sentry, que libera o empate () 'd fluxo, se necessário, extratos e descarta todos os personagens principais espaços em branco, a menos que a bandeira ios_base::skipws foi cancelado, e verifica se há erros. Se o objeto sentinela retorna false, sai imediatamente.
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.
Depois, se os retornos de sentinela objeto true, limpa
str
com 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.
Em seguida, lê caracteres de
is
e acrescenta-lhes a str
como se por str.append(1, c), até que uma das seguintes condições torna-se verdade: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.
N
caracteres são lidos, ondeN
éis.width()
seis.width() > 0
, caso contrário, éN
str.max_size()
Original:N
characters are read, whereN
isis.width()
ifis.width() > 0
, otherwiseN
isstr.max_size()
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.- a condição de fim de arquivo ocorre no
is
fluxoOriginal:the end-of-file condition occurs in the streamis
The 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()) é verdade para o próximo caractere
c
emis
(este personagem espaços em branco permanece no fluxo de entrada).Original:std::isspace(c,is.getloc()) is true for the next characterc
inis
(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 nenhum dos caracteres são extraídos então std::ios::failbit é definido em
is
, que pode lançar 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.
Finalmente, chama os.width(0) e destrói o objeto 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.
Índice |
[editar]Exceções
1)pode lançar std::ios_base::failure se uma exceção é lançada durante a saída.
2) 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.
pode lançar std::ios_base::failure se não são personagens extraídos de
is
(por exemplo, o fluxo está no final do arquivo, ou seja constituído por espaços em branco apenas), ou se uma exceção é lançada durante a entrada.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.
[editar]Parâmetros
os | - | um fluxo de saída de caractere 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 | - | um fluxo de entrada de caracteres 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 | - | a string a ser inserido ou extraído 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. |
[editar]Valor de retorno
1) os
2) is
[editar]Exemplo
#include <iostream>#include <string> int main(){std::string greeting ="Hello, whirled!"std::cout<< greeting <<'\n';}
Saída:
Hello, whirled!