#include <iostream>
#include <iomanip>
using namespace std;
ostream & currency(ostream & output)
{
output << "RS ";
return output;
}
int main()
{
cout << currency << 7864.5;
return 0;
}
OUTPUT :
RS 7864.5
I don’t understand how this seems to work i.e just the name of the function currency
is used to invoke the function.
isn’t this supposed to be like currency(cout) but using it gives output.
RS 1054DBCC7864.5
The function
currency()is a manipulator: The stream classes have special overloaded output operators taking functions with a specific sigunature as argument. They look something like this (with the templatization elided):That is,
currencyis passed as a function pointer which gets called with the stream as its argument.