Re: Streaming message box
CedricCicada@gmail.com wrote:
I tried the show manipulator idea. Here's my implementation:
#include "stdafx.h"
#include "MessageBoxExt.h"
#include <sstream>
#include <typeinfo>
using namespace std;
ostream& show(ostream& ostrm)
{
try
{
ostringstream& os = dynamic_cast<ostringstream&>(ostrm);
AfxMessageBox(os.str().c_str());
}
catch (bad_cast bc)
{
AfxMessageBox(bc.what());
}
return ostrm;
}
I am getting a Microsoft C++ Exception on the dynamic cast. The catch
block is not being executed. Can someone tell me why?
Mihai, thank you very much for your idea. Your idea is closer to what
I was originally thinking of, but the stringstream version appeals to
me more. Your comments about localization were very helpful, and the
link you provided is now in my Favorites list, since I'm going to have
to be seriously worried about localization very soon.
RobR
RobR:
Could it be that dynamic_cast is confused by the fact that ostringstream
is a typedef? Have you tried it with static_cast?
David Wilkinson