istream_iterator

Hello,
Can some one give me an example of using the istream_iterator under VC6.

Tank's
arnon@zzn.com
arnonayalAsked:
Who is Participating?
 
nietodConnect With a Mentor Commented:
fstream Fil("GileName",ios::in);
istream_iterator Itr(Fil);

while (true)
{
   ++Itr; // get next item.
   if (Fil.eof())
      break;
   char Ch = *Itr; // Get item just read.
}

Its sort of like a pointer into the input stream.  You can get what it points at by using * or ->.  You can move it to the next item in the stream using ++.

Let me know if you have any questions.
0
 
arnonayalAuthor Commented:
Hello, Thanks to the fast response. I stiil have problem to compile it.
My code:
-------------------------------------
#include <iostream>
#include <fstream>
#include <iterator>

using namespace std;

void main(int argc, char* argv[])
{
      fstream Fil("GileName",ios::in);
      istream_iterator Itr(Fil);

      while (true)
      {
        ++Itr; // get next item.
            if (Fil.eof())
        break;
      char Ch = *Itr; // Get item just read.
      }
}

------------------------------------
I get errors:
C2955: 'istream_iterator' : use of class template requires template argument list(180) : see declaration of 'istream_iterator'
C2514: 'std::istream_iterator' : class has no constructors.

Thank's again, Arnon
0
 
nietodCommented:
stream_iterator Itr(Fil);

should be

stream_iterator<char> Itr(Fil);

That will fix the first problem and I hope the second one too.
0
 
arnonayalAuthor Commented:
Thanks.
0
All Courses

From novice to tech pro — start learning today.