I'm searching how to overload the operator<< in a subclass of ofstream (not ostream!)
I can't understand why it work with ostream but not with ofstream (and book example are for ostream )
Look one sample:
#include<iostream>
using namespace std;
class x
{
public:
int xx;
};
ostream& operator<<(ostream& c,x& a)
{
return c<<a.xx;
}
int main()
{
x a;
a.xx=0;
cout<<a<<endl;
return 0;
} John Fill
Doing it for fstream works fine. I have always put the overloading into the .h files or into the structs i create and just inline them. Here is an example.
friend ofstream& operator << (ofstream& o,
<user defined type> my_type)
{
...// output my_type how you want (output to "o"
return o;
}
and in the "test.fichier" file I want to have:
SysLog Output
So the problem is:
How to make an operator like this one
friend ofstream& operator << (ofstream& o,
<user defined type> my_type)
{
...// output my_type how you want (output to "o"
return o;
}
returning the string o = "Syslog "+mystring;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.