|
-
February 4th, 2003, 11:13 PM
#1
Question about input iterator on the same input stream.
Hi, everyone!
Here is a simple STL program. It uses two input iterators
to use on the same input file. I do not understand why the
output is looking like this.
Here are the source codes,
--------
#include <iterator>
#include <fstream>
#include <iostream>
using namespace std;
void main()
{
// c:\\file1.txt: 0 1 2 3
ifstream ifile ("c:\\file1.txt");
istream_iterator<int> r (ifile);
istream_iterator<int> s (ifile);
(r==s) ? cout << "equal" : cout << "not equal";
cout << endl;
++r;
++s;
cout << *r << endl;
cout << *s << endl;
(r==s) ? cout << "equal" : cout << "not equal";
cout << endl;
}
--------
Here are the outputs,
--------
equal
2
3
equal
--------
Thanks in advance,
George
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|