I think the following code can be used to create manipulators.
#include<iostream>
ostream & symbol(ostream & output)
{
return output << "\tRs";
}
it is working fine. The following statement
cout << "Total amount: " << 567 << symbol;
gives the output
Total amount: 567 Rs
But I didn't understand why it is working. I have the following information about operator overloading in C++.
only existing operators can be overloaded. New operators cannot be created. But the symbol is not existing operator.
In the statement (cout << "Total amount: " << 567 << symbol;), it seems that << is the overloaded operator and symbol is a variable/object. But I didn't declare symbol as variable/object.
why are they using the return statement (return output << "\tRs";)?. I think (return "\tRs";) or (output << "\tRs";) should work.( I tried but not working :) )
Actually I don't know how the above code is working. Is there anybody to explain the working of the above operator overloading?