用c ++写入函数内部的ostream

时间:2011-03-11 20:58:32

标签: c++

考虑以下功能:

void writer(ofstream &output) {
output << "a string to write" << endl;

}

但是当我试着调用它时,我得到一个'&lt;&lt;'的错误没有定义。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:7)

添加#include <fstream>或将ofstream更改为ostream

很可能你缺少一个include,所以ofstream只是向前声明。