std::istream_iterator
De cppreference.com
<metanoindex/>
<tbody> </tbody>| Definido no cabeçalho <iterator>
|
||
template< class T, class CharT = char, class Traits = std::char_traits<CharT>, class Distance = std::ptrdiff_t > class istream_iterator: public std::iterator<std::input_iterator_tag, T, Distance, const T*, const T&> |
||
std::istream_iterator é um iterador de entrada única passagem que se lê objetos sucessivos de T tipo do objeto std::basic_istream para o qual foi construído, chamando o operator>> apropriado. A operação de leitura actual é executada quando o iterador é incrementado, e não quando é dereferenced. O primeiro objeto pode ser lido quando o iterador é construído ou quando o dereferencing primeiro é feito. Caso contrário, dereferencing só retorna uma cópia do objeto mais recentemente li.Original:
std::istream_iterator is a single-pass input iterator that reads successive objects of type T from the std::basic_istream object for which it was constructed, by calling the appropriate operator>>. The actual read operation is performed when the iterator is incremented, not when it is dereferenced. The first object may be read when the iterator is constructed or when the first dereferencing is done. Otherwise, dereferencing only returns a copy of the most recently read 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.
O padrão construído
std::istream_iterator é conhecido como o fim-de-fluxo iterador. Quando um std::istream_iterator válido atinge o final do fluxo de base, torna-se igual ao iterador fim-de-fluxo. Dereferencing ou incrementá-lo ainda mais invoca comportamento indefinido.Original:
The default-constructed
std::istream_iterator is known as the end-of-stream iterator. When a valid std::istream_iterator reaches the end of the underlying stream, it becomes equal to the end-of-stream iterator. Dereferencing or incrementing it further invokes undefined behavior.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.
Uma implementação típica de
std::istream_iterator detém dois membros de dados: um ponteiro para o objeto associado e std::basic_istream o valor mais recentemente lido do tipo T.Original:
A typical implementation of
std::istream_iterator holds two data members: a pointer to the associated std::basic_istream object and the most recently read value of type T.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.
Ao ler caracteres, std::istreambuf_iterator é mais eficiente, uma vez que evita a sobrecarga de construção e destruindo o objeto sentinela uma vez por personagem.
Original:
When reading characters, std::istreambuf_iterator is more efficient, since it avoids the overhead of constructing and destructing the sentry object once per character.
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.
Tipos de membro
Tipo de membro
Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
char_type
|
CharT
|
traits_type
|
Traits
|
istream_type
|
std::basic_istream<CharT, Traits>
|
Funções de membro
constrói um novo istream_iterator Original: constructs a new istream_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
(destructor) (declarada implicitamente) |
destructs an istream_iterator, including the cached value (função pública membro) |
obtém uma cópia do atual element accesses um membro do elemento atual Original: obtains a copy of the current element accesses a member of the current element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
avança a istream_iterator Original: advances the istream_iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
Não-membros funções
compara dois istream_iterators Original: compares two istream_iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (modelo de função) | |
Herdado de std::iterator
Member types
Tipo de membro
Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
value_type
|
T
|
difference_type
|
Distance
|
pointer
|
const T*
|
reference
|
const T&
|
iterator_category
|
std::input_iterator_tag
|
Exemplo
#include <iostream>
#include <sstream>
#include <iterator>
#include <numeric>
int main()
{
std::istringstream str("0.1 0.2 0.3 0.4");
std::partial_sum(std::istream_iterator<double>(str),
std::istream_iterator<double>(),
std::ostream_iterator<double>(std::cout, " "));
}
Saída:
0.1 0.3 0.6 1
