将 ifstream 传递给 C++ 中的函数
我正在尝试为基因测序项目构建 16 个不同的后缀树。它们是在 main 中构建的,因此
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:在构造函数中
Tree::Tree(std::ifstream&)
:
suffix.cpp:12: 错误:无效使用未定义类型 struct std::basic_ifstream; >
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iosfwd:89: 错误: struct std 的声明::basic_ifstream; >
suffix.cpp:15: 错误:无效使用未定义类型 struct std::basic_ifstream; >
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iosfwd:89: 错误: struct std 的声明::basic_ifstream; >
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您已经#included;而不是 在你的源文件中。
It looks like you have #included <iosfwd> instead of <fstream> in your source files.
您是否 #include了
fstream
标头?Have you #included the
fstream
header?