Programming Taskbook


E-mail:

Password:

User registration   Restore password

Russian

SFedU SMBU

Electronic problem book on programming

©  M. E. Abramyan (Southern Federal University, Shenzhen MSU-BIT University), 1998–2026

 

PT for STL | Iterators for the pt stream

PrevNext


Iterators for the pt Stream

Starting from version 4.15 of the Programming Taskbook electronic problem book, for input and output of sequence elements of type T when performing educational tasks, you can use specialized iterators ptin_iterator<T> and ptout_iterator<T> respectively. These iterators possess the same properties as the standard stream iterators istream_iterator<T> and ostream_iterator<T>.

Properties of the input iterator that coincide with the analogous properties of stream iterators:

  • type T defines the type of the sequence elements;
  • reading a sequence element from the pt stream is performed at the initial moment of working with the iterator, and then with each increment operation ++;
  • there are two variants of the ++ operation: prefix increment (++i) and postfix increment (i++);
  • the * operation returns the last read value, and this operation can be used repeatedly to obtain the same value;
  • the end-of-sequence iterator is created using a parameterless constructor;
  • upon reaching the end of the sequence, the iterator becomes equal to the end-of-sequence iterator, subsequent calls to the increment operation are ignored, and a call to the * operation always returns the value of the last read element of the sequence.

Properties of the output iterator that coincide with the analogous properties of stream iterators:

  • no special constructor for creating an end-of-sequence iterator is provided;
  • the * and ++ operations perform no actions and simply return the iterator itself;
  • the assignment operation of the form o = expression (where o is the name of the output iterator) writes the value of the expression to the pt stream.

Unlike the standard istream_iterator, the constructor for the ptin_iterator iterator (except for the end-of-sequence iterator constructor) has one parameter of type unsigned int, defining the size of the sequence to be read (in elements). For the special parameter value of 0, the sequence size is read from the pt stream immediately before reading the first element of the sequence. If during the size reading it turns out that the read data element is not an integer or this number is not positive, then the iterator immediately transitions to the end-of-sequence state (i.e., becomes equal to the iterator ptin_iterator<T>()).

This organization of the ptin_iterator<T> input iterators allows for easy implementation of reading multiple sequences from the pt input stream, if their size is known in advance or if the size is specified immediately before the start of the sequence.

The iterators ptin_iterator<T> and ptout_iterator<T> are used in many program templates related to the tasks included in the Programming Taskbook for STL electronic problem book.


PrevNext

 

  Рейтинг@Mail.ru

Designed by
M. E. Abramyan and V. N. Braguilevsky

Last revised:
01.01.2026