【1】问题描述
最近在写工具的时候,代码编译出现 variable 'std:ofstream’ has initializer but incomplete type 或者是 variable 'std:ifstream’ has initializer but incomplete type
【2】原因
因为没有包含fstream这个头文件。
【3】代码详解
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
int main() {
fstream f("filename");
f << 20;
f.close();
}
上面的代码,如果不包含fstream头文件,就无法完成编译。
搞定!
allenlinrui
2014/02/21
本文解决了一个常见的编程问题:使用ofstream或ifstream时遇到的变量初始化但类型不完整的问题。通过引入必要的头文件,即可轻松解决此类编译错误。
6100

被折叠的 条评论
为什么被折叠?



