Simply change the order of the parameters in the overloaded operator.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
class myClass {
friend ostream &operator<<(const myClass&, ostream&);
int data;
public:
myClass(int d) : data(d) {}
};
ostream &operator<<(const myClass& obj, ostream& file) {
return file << obj.data;
}
int main()
{
myClass obj1(5);
obj1 << cout;
cin.get();
return 0;
}
Now keep in mind, there is no way to prevent the right shift operator from reading left to right, so chaining becomes impossible without a reference to the ostream, for instance
Code:
obj1 << obj1 << cout; // Doesn't work
You also can't, as you seem to be trying to do, make it a member function. It's simply not allowed in the language to change the number of arguements.