Link to home
Start Free TrialLog in
Avatar of IainHere
IainHere

asked on

<< to AfxMessageBox / cout

My program can be run from the command line or using an MFC GUI.  During calculation, I would like error messages to be directed either to cout or popped up in a MessageBox, depending on how the user is running it.  How best to do this?

My current plan is to set a flag on startup, and check it every time there is output, something like:

void ShowErrorMessage(std::string msg)
{
 if flag
   std::cout << msg;
 else
   MessageBox(msg);
}

This feels wrong - rather than
ShowErrorMessage("my message");
I'd like to be doing
errOutput << "My message";

Is this a better way?  How would I best implement it?  Although at the moment, the program will only run on Windows, I'd like to make the code as platform independent as possible.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IainHere
IainHere

ASKER

No wonder you made 10e6 points - concise and correct.

Thanks a million :-)
Thanks :o)