简体   繁体   English

如何在VC ++中的控制台模式下显示错误消息?

[英]how to Display error message in console mode in VC++?

I am working on a VC++ windows application which support GUI as well as non-GUI based execution. 我正在一个VC ++ Windows应用程序上工作,该应用程序支持GUI以及基于非GUI的执行。 The non GUI based execution is designed for console mode purpose. 非基于GUI的执行旨在用于控制台模式。 Now, if I executed that application in GUI mode I can show message box for user acknowledgement in case of error or exception. 现在,如果我以GUI模式执行该应用程序,则可以在出现错误或异常的情况下显示消息框供用户确认。

But in Console mode, I have to execute like 但是在控制台模式下,我必须像

c:> myapp.exe -options -MS Yes c:> myapp.exe-选项-MS是

If user type the above command without "-options"keyword. 如果用户键入上述命令,但不带“ -options”关键字。 I want to display a error message in console mode. 我想在控制台模式下显示错误消息。

The idea is to check that the options key is entered and exit if not. 想法是检查是否已输入options键,如果未输入则退出。 The approximate code of this solution: 此解决方案的近似代码:

int main(int argc, char** argv)
{
    if (...) // Check for options presence here
    {
        cerr << "Myapp should be run as myapp.exe -options -MS Yes" << endl;
        return 0;
    }
    ... // Some actual work here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM