【发布时间】:2012-08-20 12:28:56
【问题描述】:
可能重复:
Why do I need to include both the iostream and fstream headers to open a file
我写了这段代码:
#include <iostream>
int main()
{
std::ofstream file_out("file.txt");
file_out.close();
return 0;
}
std::ofstream 是在<iostream> 中定义的,但是编译这段代码我得到以下错误:
error: variable 'std::ofstream file_out' has initializer but incomplete type
我发现如果我还包含<fstream>,错误就会消失并且代码可以编译。如果std::ofstream 包含在<iostream> 中,为什么还要包含<fstream>?
【问题讨论】:
标签: c++ stream iostream fstream