public member function
<iterator>

std::istream_iterator::operator++

(1)
istream_iterator& operator++();
(2)
istream_iterator  operator++(int);
前進迭代器位置
istream_iterator 向前移動一個位置。

在內部,該函式從其*關聯的流*中提取一個元素,並將其儲存起來,以便在解引用時返回。

引數

無(第二個版本過載了字尾遞增運算子)。

返回值

字首遞增版本(1)返回*this
字尾遞增版本(2)返回呼叫前*this的值。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// istream_iterator example
#include <iostream>     // std::cin, std::cout
#include <iterator>     // std::istream_iterator

int main () {
  double value1, value2;
  std::cout << "Please, insert two values: ";

  std::istream_iterator<double> eos;              // end-of-stream iterator
  std::istream_iterator<double> iit (std::cin);   // stdin iterator

  if (iit!=eos) value1=*iit;

  ++iit;
  if (iit!=eos) value2=*iit;

  std::cout << value1 << "*" << value2 << "=" << (value1*value2) << '\n';

  return 0;
}

資料競爭

修改物件。
返回的迭代器可用於訪問或修改指向的元素。

異常安全

基本保證:如果丟擲異常,物件處於有效狀態。

另見