M
Michal
Hallo group members
I wonder what is the difference between the two.
I can read that:
Input iterators are iterators especially designed for sequential input operations, where each value
pointed by the iterator is read only once and then the iterator is incremented.
I also can read:
A Forward Iterator is an iterator that corresponds to the usual intuitive notion of a linear sequence of values. It is possible to use
Forward Iterators (unlike Input Iterators and Output Iterators) in
multipass algorithms.
So my idea is that maybe dereferencing input iterator makes it
automatically move one step forward, while the same action on forward
iterator does not move it.
Unfortunatelly this is not true:
#include <fstream>
#include <iterator>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
ifstream f("/tmp/m.txt");
istream_iterator<int> a(f);
cout << *a << *a << *a;
cout << *a << *a << *a;
++a;
return 0 ;
}
Starting program: /tmp/p3
111111
Program exited normally.
So what is the difference then?
best regards,
Michal
I wonder what is the difference between the two.
I can read that:
Input iterators are iterators especially designed for sequential input operations, where each value
pointed by the iterator is read only once and then the iterator is incremented.
I also can read:
A Forward Iterator is an iterator that corresponds to the usual intuitive notion of a linear sequence of values. It is possible to use
Forward Iterators (unlike Input Iterators and Output Iterators) in
multipass algorithms.
So my idea is that maybe dereferencing input iterator makes it
automatically move one step forward, while the same action on forward
iterator does not move it.
Unfortunatelly this is not true:
#include <fstream>
#include <iterator>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
ifstream f("/tmp/m.txt");
istream_iterator<int> a(f);
cout << *a << *a << *a;
cout << *a << *a << *a;
++a;
return 0 ;
}
Starting program: /tmp/p3
111111
Program exited normally.
So what is the difference then?
best regards,
Michal