Shaul Karl <[EMAIL PROTECTED]> writes: > > > int main() > > > { > > > ifstream input("main.cc"); > > > istream_iterator<string> iter1(input), iter2, eof; > > > iter1 = find(iter1, iter2, "main()"); > > > iter2 = find(iter1, eof, "}"); > > ^^^^ > > These are your problem. If you put > > > > cout << "iter1: " << *iter2 << "\titer2: " << *iter2 << "\n"; > > > > immediately following those find statements, you'll get the output > > > > iter1: } iter2: } > > > > which means the find statements aren't doing what you want. The for > > loop is working fine, however. > > You didn't get the expected printing of *iter1 and *iter2 because you > have a typo. The printing line uses *iter2 where you wanted *iter1.
Ugh, yeah, you're right. Sorry about that. So the find function does work correctly, but the for loop is broken. > As for the initialization of iter2 and eof, as far as I know they > assume the default value, which is EOF. That appears to be true on my system. > Beside, having it compiled without errors/warnings although gdb comment > that there is no != method is odd. As someone else mentioned, (iter1 == iter2) even though (*iter1 != *iter2). It seems as though istream_iterator's are weird; for example, you can't seem to walk through the stream: cout << "iter1: " << *iter1 << "\titer2: " << *iter2 << "\t++iter1: " << *(++iter1) << "\n"; produces: iter1: main() iter2: } ++iter1: main() comp.lang.c++ would be a better place to ask this question (ie. they'll probably give you a correct answer). -- Brian Nelson <[EMAIL PROTECTED]> [EMAIL PROTECTED] http://bignachos.com