Hooking ostream?

Hello,
I'm wondering if there's a way to hook ostream (cout) so if I write
cout <<"sometext"; a callback function would be called and I could do something with the input. The reason I want to do is to display cout text with MessageBox function. Any ideas?

Thanks for help.
It seems that it is possible to overwrite operators:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

std::ostream& operator << (std::ostream& out, const char* str){
	out << 5;
	return out;
}

int main(){
	std::cout << "hello";//I get 5 here
	std::cin.get();
	return 0;
}

But I have a feeling that it is not a good idea.
If you want to overwrite output operations then why do you need ostream at all?
Why not write your own class?
Topic archived. No new replies allowed.