There is this code:
 class precision {   
       int digits;
       public:   precision(int digits) : digits(digits) {}
       friend ostream& operator<<(ostream& os, const precision& p) {
           os.precision(p.digits);
           return os;
       }
   };
It's meant to make a command line like:
cout << precision(5) << a << " " << precision(2) << b << endl; 
to work, instead of doing:
cout.precision(5);
cout << a << " ";
cout.precision(2);
cout << b << endl
I fail to understand how the friend function part works. Why is it a friend? And how come it receives two arguments instead of one? THanks.
 
    