Passing ifstream to a function in C++
c++, ifstream
Solution
Have you #included the `fstream` header?
Problem
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> >`