Is it possible to capture cout in a way so that every standard output (cout << "example";) automatically calls a function (myfunc("example");)?
Is it possible to capture cout in a way so that every standard output
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One way would be to create a class which had the appropriate
operator<<overloads and create a global instance calledcoutand tousing std::whateverinstead ofusing namespace std;. It would then be easy enough to switch back and forth from your customcouttostd::cout.That’s just one solution though (which may require a decent amount of work, more than you want to spend), I’m sure other people know better ways.