variable 'std:ofstream' has initializer but incomplete type

来源:互联网 发布:papi酱起诉 知乎 编辑:程序博客网 时间:2024/05/29 14:48


variable 'std:ofstream’ has initializer but incomplete type

或者是variable 'std:ifstream’ has initializer but incomplete type

其原因是因为没有包含fstream这个头文件。

Cpp代码 
  1. #include<fstream>  
  2. #include<iostream>  
  3. #include<string>   
  4. using namespace std;  
  5. int main()  
  6. {  
  7. fstream f("filename");  
  8. f << 20;  
  9. f.close();   
  10. }   

上面这段代码如果没有那个<fstream>就会有标题的错误。