i have function acts cout options.
eg : myfunc(0) << "cats drink milk " << 2 << endl;
when 0, there shouldn't output
when :
myfunc(1) << "cats drink milk " << 2 << endl;
i should see output "cats drink milk2". read several forums ostream needs used, not sure how can use purpose. myfunc class basically, 1, 0 options constructor.
i have seen things this, don't how works.
log& operator<< (std::ostream &(*f)(std::ostream &)){ cout << *f; return *this; }
any appreciated.
it goes this:
class coutplus { public: coutplus(int& i) : m_bon(i) {} template<class t> coutplus& operator<<(const t& val) { if (m_bon) std::cout << val; return *this; } private: bool m_bon; };
you decide empty constructor , assignment, , whether implement other ostream's member functions.