c++ - 对指针使用输出流重载运算符

标签 c++ instance overloading

我有一份类(class)作业要提交,我几乎全部完成了。但我被困在 我必须使用输出流运算符将类实例读取到文件中。输出流运算符将实例作为参数,但我需要 将它用作指向实例的指针。有什么帮助吗?

我的输出流运算符实现是:

ostream& operator<<(ostream& out, sequence &s)
{
    out<<s.number_of_samples;//<<s.samples;
    s.samples=new float [s.number_of_samples];
    for(int i=0; i<s.number_of_samples; i++) out<<s.samples[i];
    return(out);
}

它将实例读取到文件的位是:

ofstream output_filtered_samples_file("output.txt");
sequence* filtered_sequence = test_FIR.apply_filter(test_sequence);
output_filtered_samples_file<<filtered_sequence;

完整代码是 http://ideone.com/V0Xavo

最佳答案

取消引用指针。 . .

output_filtered_samples_file<<*filtered_sequence;

关于c++ - 对指针使用输出流重载运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34047004/

相关文章:

C# EventHandler - 没有重载与委托(delegate)匹配(嗯?)

c++ - 如何在某些头文件(嵌套类)的 cpp 文件中包含我的实现

C# - 为类的所有实例添加事件处理程序

C++ - 顺序多线程输出

c++ - 我如何声明我的类的实例?

haskell - 为什么在 Haskell 中声明参数化数据类型?

c++ - C++中标准库函数的函数重载

c# - 在 C# 中重载属性

c++ - IFileDialog/IShellItem::GetDisplayName 不适用于 Windows 7 库

c++ - 加法运算符没有影响