命令行应用程序中的返回值行为 [英] Return values behaviour in Command Line applications

查看:122
本文介绍了命令行应用程序中的返回值行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为命令行应用程序编写代码,该应用程序通过调用不同的功能来执行多项操作.我在成功和失败时从主函数返回0值,我正在打印一条错误消息并返回-1.我想问的是,Visual C ++会根据从主函数返回的错误代码在命令行上打印自己的错误消息?

I am writing a code for a command line application which perform several operations by calling different functions. I am returning 0 value from the main function on success and on failure I am printing an error message and returning -1. The thing I want to inquire is that is Visual C++ prints its own error messages on the command line depending on the error codes returned from the main function?

推荐答案

对不起,我不要以为我理解您的问题.
您是否希望命令窗口在返回数字值时自动打印消息?
这与C ++无关,但与命令外壳无关.如果返回一个值,那么这就是C ++应用程序的结尾. C ++运行时除了返回它外不执行任何操作.
尝试在讨论命令外壳程序或Windows Shell的论坛或新闻组中进行询问.

最简单的方法是自己进行翻译然后在命令行上打印正确的消息.
这样,您还可以打印有助于用户诊断问题的上下文信息.
Sorry I don't think I understand your question.
Do you want the command windows to automatically print messages if you return a numerical value?
This has nothing to do with C++, but with the command shell. If you return a value, then that's the end of your C++ app. The C++ runtime doesn't do anything with it except returning it.
Try asking in a forum or newsgroup that discusses the command shell or windows shell.

The easiest thing to do is to do the translation yourself and then print the correct message to the command line.
That way you can also print contextual information that will help the user diagnose the problem.


这篇关于命令行应用程序中的返回值行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆