variable 'std:ofstream’ has initializer but incomplete type
或者是variable 'std:ifstream’ has initializer but incomplete type
其原因是因为没有包含fstream这个头文件。
#include<fstream> #include<iostream> #include<string> using namespace std; int main() { fstream f("filename"); f << 20; f.close(); }上面这段代码如果没有那个<fstream>就会有标题的错误。