[BLAST_ANAWARE] ifstream question

From: Peter Karpius (karpiusp@einstein.unh.edu)
Date: Wed Feb 16 2005 - 13:11:12 EST


I am have declared an object of type ifstream so that I may read in data
from a file (i.e. H.Arenhoevel's and D. Phillips theory pts). I wrote a
small test program which worked like a charm at UNH - but when I try to
run it at Bates it fails on the unget() function below. The top line of
the data files is something like:
#Q2 GC GQ GM etc.

         it is a header that I do not want to read in, I only want the
numbers that follow. So the code grabs the first character with get(ch),
stores it, and puts it back with unget(). It then checks if it is a '#' -
if so it ignores the line.

Now I could:

1) delete this header line
2) figure out why unget() does not work and fix it.

         I am asking for help with the latter. Here is the piece of code:

////////////////////////////////////////////////////////////
  ifstream inFile(file); //this creates the input stream object

     if(!inFile) // ensures that the file stream is good
         {
             cout << endl << "Failed to open file " << file << "\n";
             return 1;
         }

     char ch;
     char line[200];
     for (i=0;i<100;i++)
         {
             inFile.get(ch);
             inFile.unget();

             if (ch == '#'){
                 inFile.getline(line, 82);

             }
             else {

                 inFile >> thetae[i];
                 inFile >> Q2[i];
                 inFile >> GC[i];
                 ....

                  }
        }
///------------------------------------------------------
         again, it works in this exact form at UNH - any ideas?

                                 Pete

P.S. The output is:

Processing theory.C...
READING VALUES FROM karpius_form_b_n.dat
Error: Can't call ifstream::unget() in current scope FILE:theorycurves.h
LINE:41
Possible candidates are...
filename line:size busy function type and name (in ifstream)
filename line:size busy function type and name (in fstreambase)
filename line:size busy function type and name (in ios)
filename line:size busy function type and name (in istream)
filename line:size busy function type and name (in ios)
Error: Symbol inFile is not defined in current scope FILE:theorycurves.h
LINE:41
Error: Failed to evaluate inFile.unget()Possible candidates are...
filename line:size busy function type and name
*** Interpreter error recovered ***

----------------------------------------------
Pete Karpius
Graduate Research Assistant
Nuclear Physics Group
University of New Hampshire
phone: (603)978-6152
FAX: (603)862-2998
email: karpiusp@einstein.unh.edu
http://pubpages.unh.edu/~pkarpius/homepage.htm
----------------------------------------------



This archive was generated by hypermail 2.1.2 : Mon Feb 24 2014 - 14:07:32 EST