tags:

views:

122

answers:

2

I'm trying to build 16 different suffix trees for a gene sequencing project. They're being built in main as such

int main()
{  
  ifstream fp;  
  fp.open("filepath", ifstream::in);  
  Tree I(fp);  
  fp.close();

I'm attempting to use them in my constructor with this code:

Tree::Tree(ifstream &fp)   
{  
  string current = "";  
  char* line;  
  fp.getLine(line, 100); //ignore first line  
  for(int i=0; i<100; i++)     
    {  
      char temp = (char)fp.get();  
      if(temp=='\n')i--;  
      else current+=temp;  
    }  
  insert(current);  
  while(fp.good())  
    {  
      current = current.substr(1,99);  
      char temp = (char)fp.get();  
      if(temp=='\n')temp=(char)fp.get();  
      if(temp==EOF) break;  
      current+=temp;  
      insert(current);  
    }  
}  

When I attempt to compile, I get these errors for every instance in which I use fp:

suffix.cpp: In constructor Tree::Tree(std::ifstream&):
suffix.cpp:12: error: invalid use of undefined type struct std::basic_ifstream<char, std::char_traits<char> >
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iosfwd:89: error: declaration of struct std::basic_ifstream<char, std::char_traits<char> >
suffix.cpp:15: error: invalid use of undefined type struct std::basic_ifstream<char, std::char_traits<char> >
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iosfwd:89: error: declaration of struct std::basic_ifstream<char, std::char_traits<char> >

+2  A: 

Have you #included the fstream header?

sth
+1. `std::basic_ifstream` was forward declared in `<iosfwd>`, but `<fstream>` isn't actually included in the source file where the code is located.
Billy ONeal
I'd included it in my main, but not in the file with the offending function. Thanks for the help.
Jesse Welch
+2  A: 

It looks like you have #included <iosfwd> instead of <fstream> in your source files.

bmatthews68