【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