C语言 在 Visual Studio 2010 中传递命令行参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3697299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing command line arguments in Visual Studio 2010?
提问by Fahad
I am working on a C project and can not figure out how to pass command line arguments to my main function in Visual Studio 2010 Express Edition. I want to debug - how do these command line arguments work?
我正在处理一个 C 项目,无法弄清楚如何将命令行参数传递给 Visual Studio 2010 Express Edition 中的主函数。我想调试 - 这些命令行参数如何工作?
回答by Andrew Cooper
- Right click your project in Solution Explorer and select Properties from the menu
- Go to Configuration Properties -> Debugging
- Set the Command Arguments in the property list.
- 在解决方案资源管理器中右键单击您的项目,然后从菜单中选择属性
- 转到配置属性-> 调试
- 在属性列表中设置命令参数。


回答by Alex Hart
Under Project->Properties->Debug, you should see a box for Command line arguments (This is in C# 2010, but it should basically be the same place)
在 Project->Properties->Debug 下,您应该会看到一个命令行参数框(这是在 C# 2010 中,但基本上应该是同一个地方)
回答by Serge Voloshenko
Visual Studio 2015:
视觉工作室 2015:
Project=>Your Application Properties. Each argument can be separated using space. If you have a space in between for the same argument, put double quotes as shown in the example below.
Project=>您的应用程序Properties。可以使用空格分隔每个参数。如果同一个参数之间有空格,请按以下示例所示放置双引号。
static void Main(string[] args)
{
if(args == null || args.Length == 0)
{
Console.WriteLine("Please specify arguments!");
}
else
{
Console.WriteLine(args[0]); // First
Console.WriteLine(args[1]); // Second Argument
}
}
回答by msc
回答by mic
Visual Studioe.g. 2019 In general be aware that the selected Platform (e.g. x64) in the configuration Dialogis the the same as the Platform You intend to debug with! (see picture for explanation)
Visual Studioeg 2019 通常请注意,配置对话框中选择的平台(例如 x64)与您打算调试的平台相同!(见图片解释)
Greetings mic enter image description here
问候麦克风 在此处输入图像描述

