我正在尝试编写一个将信息写入流的函数。我需要能够将其传递给stringstream或ostream。我尝试使用F(std::ios* out)
声明该函数,但随后在使用<<
运算符写入该函数时,出现此错误:error: no match for operator<<
。我应该如何声明该功能?
最佳答案
我认为您正在寻找c++ references
void F(std::ostream& out)
{
}
会成功的请注意,这将假定
char
流,否则:template <typename Char/*=char*/, typename Traits/*=std::char_traits<CharT> */>
void F(std::basic_ostream<Char, Traits>& os)
{
}