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

GSt*_*Sto 0 c++

考虑以下功能:

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

}
Run Code Online (Sandbox Code Playgroud)

但是当我试着调用它时,我得到一个"<<"未定义的错误.我怎样才能解决这个问题?

Eri*_*rik 7

添加#include <fstream>或更改ofstreamostream

很可能你缺少一个包含,因此只有前向声明.