且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C ++程序中使用命令行参数?

更新时间:2023-02-22 11:15:36

为简单起见,我假设您使用的是Windows 7。

For the purpose of simplicity, I will assume you are using Windows 7.

最简单的方法是打开DOS框,然后将应用程序拖放到该框上。这将插入可执行文件的路径。之后,您可以开始键入您希望传递的命令行参数。最终应该看起来像这样:

The simplest way is to open a DOS box and then drag-n-drop you application on to it. This will insert the path to your executable. Following that, you may begin typing the command line arguments you wish to pass it. It should end up looking something like this:

C:\Users\cscott> "C:\Users\cscott\Documents\myApp.exe" argument1 argument2

注意:如评论中所述,这在Windows Vista上不起作用,这在撰写本文时我还没有意识到。

Note: As mentioned in the comments, this does not work on windows vista, a fact I was unaware of at the time of writing.