例子:


#include <iostream>
#include <string>

using namespace std;

int main(int argc, char** argv)
{
ifstream ifs("test.txt");

string str;
while (getline(ifs, str))
{
cout << str << endl;
}

return 0;
}


程序输出:


~ # gcc test.cpp
test.cpp: In function ‘int main(int, char**)’:
test.cpp:8: error: variable ‘std::ifstream ifs’ has initializer but incomplete type
~ #



这里是由于缺少头文件fstream

加入#include <fstream>

总结:这里看到了gcc的提示,incomlete type不完整的类型。

一般这种问题是由于缺少头文件引起的,经常会遇到这样子的提示,所以记住发生incomplete type的原因。