我写了这段代码:
#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>
错误消失并且代码编译。为什么我要包括<fstream>
if std::ofstream
is included in <iostream>
?