Aren't the increment operator and comparison work with
istream_iterator<string>?
The following program tries to copy part of its own source file
(main.cc) to cout.
$ cat main.cc
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int main()
{
ifstream input("main.cc");
istream_iterator<string> iter1(input), iter2, eof;
iter1 = find(iter1, eof, "main()");
iter2 = find(iter1, eof, "}");
for (; iter1 != iter2; iter1++) cout << *iter1;
cout << "\n";
}
$
When executing it, all I get is the newline from the last statement:
$ ./main
$
Further more, adding the lines
cout << "*iter1 = " << *iter1 << " *iter2 = " << *iter2 << '\n';
iter1 == iter2 ? cout << "iter1 == iter2\n"
: cout << "iter1 != iter2\n";
just before the for loop reveals that
*iter1 = main() *iter2 = }
iter1 == iter2
How could this be? Aren't input iterators supposed to be somewhat like
input pointers?
Compilation line is
g++ -Wall -g -o main main.cc
g++ is either 2.95 or 3.0, I tried with both.
--
Shaul Karl
email: shaulka(at-no-spam)bezeqint.net
Please replace (at-no-spam) with an at - @ - character.
(at-no-spam) is meant for unsolicitate mail senders only.
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]