1. You declare it to be a friend only in the class body.
Code:
class kom
{
friend ostream& operator<<(ostream& out, const kom&);
//other data
}; //<===Don't forget the semicolon after the class declaration
you define it elsewhere without the friend directive because outside the class it would mean it's a friend to the global scope, which wouldn't be much use
Code:
class kom
{
//other data
};
//defined outside the scope of kom
ostream& operator<<(ostream& out, const kom&)
{
//don't use cout, cout is the standard output, you want
//to use any output stream such as a file or string stream or any
//other stream object
out <<a<<b<<d<<x<<y<<'\n';
return out; //remember to return it.
}
now you can use it as such
Code:
int main()
{
ofStream outfile("output.txt");
ostringstream outsstream;
kom aKom;
//do whatever it is you want with your class
cout << aKom;
outfile << aKom;
outsstream << aKom;
return 0;
}