This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: fstream/ios (hopefully not OT)
- From: John Love-Jensen <eljay at adobe dot com>
- To: Wagner Matthias <necrox at gmx dot at>, <gcc-help at gcc dot gnu dot org>
- Date: Thu, 30 Jan 2003 06:45:31 -0600
- Subject: Re: fstream/ios (hopefully not OT)
Hi Wagner,
You have something really unusual (in an odd / bad way) in your class. You
shouldn't use the operator << on the ofstream, you should use it on the
ostream.
If you want a binary output (not indicated by your example, but just in
case), you shouldn't use the operator << mechanism, rather you should create
a read method for input, and a write method for output.
My modified version is below, and the problem goes away.
Sincerely,
--Eljay
---- CLASS LISTING
#include <iostream>
using std::ostream;
class Test
{
private:
int m;
int n;
public:
Test()
: m(0), n(0) { }
Test(int a, int b = 0)
: m(a), n(b) { }
friend ostream& operator << (ostream& ofstr, const Test& a);
};
ostream& operator << (ostream& ofstr, const Test &a)
{
ofstr << a.m;
return ofstr;
}