2010-02-23 128 views
2

我正在尝试为基因测序项目构建16个不同的后缀树。他们正在建造的主这样将ifstream传递给C++中的函数

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

我试图在我的构造此代码使用它们:

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); 
    } 
} 

当我尝试编译,我得到这些错误的每个实例其中我使用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> >

回答

5

你有#included fstream标题吗?

+0

+1。 'std :: basic_ifstream'已在''中转发,但''实际上并未包含在代码所在的源文件中。 – 2010-02-23 02:17:40

+0

我将它包含在我的主文件中,但不包含在有问题功能的文件中。谢谢您的帮助。 – 2010-02-23 02:19:52

5

它看起来像#included <iosfwd>而不是<fstream>在您的源文件中。