René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

An STL Manipulator that calls MessageBox

#include <windows.h>
#include <sstream>
#include <ostream>

using namespace std;

ostream& message_box(ostream &os) {
  ostringstream* ost = dynamic_cast<ostringstream*>(&os);
  if (ost) ::MessageBox(NULL, ost->str().c_str(), "", MB_OK);
  return os;
}

int main() {
  ostringstream os;
  os <<  "A funny way to display a message box: " << 42 << message_box;

  return 0;
}
Make sure, you enable RTTI when you compile the program.