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::stri ng 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.
My current plan is to set a flag on startup, and check it every time there is output, something like:
void ShowErrorMessage(std::stri
{
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks :o)
ASKER
Thanks a million :-)