如何在 Xcode 中传递命令行参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39087042/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:10:02  来源:igfitidea点击:

How to Pass Command-Line Arguments in Xcode

c++xcode

提问by saulspatz

I'm trying to pass arguments to my Xcode C++ command-line tool. I think I'm following the help, and the answers I've found on Stack Overflow, but I'm not having any luck.

我正在尝试将参数传递给我的 Xcode C++ 命令行工具。我想我正在关注帮助,以及我在 Stack Overflow 上找到的答案,但我没有任何运气。

I'm using Xcode 7.2.1. I've edited the scheme to have two command-line arguments (an input file and an output file.) I've posted a screen shot of the editor below.

我正在使用 Xcode 7.2.1。我已经编辑了该方案,使其具有两个命令行参数(一个输入文件和一个输出文件)。我在下面发布了编辑器的屏幕截图。

When I run the code, it doesn't find the arguments. (I don't mean that it can't find the files on disk. The program aborts because argc is 1 instead of 3.)

当我运行代码时,它没有找到参数。(我不是说它找不到磁盘上的文件。程序中止是因为 argc 是 1 而不是 3。)

Can you tell me what I'm doing wrong?

你能告诉我我做错了什么吗?

EDIT: After playing around with it in response to the advice I received, it suddenly worked. I have no idea what changed. It works now with the dialog looking exactly like the screenshot I posted originally.

编辑:根据我收到的建议玩弄它后,它突然起作用了。我不知道发生了什么变化。它现在可以与我最初发布的屏幕截图完全一样的对话框使用。

enter image description here

在此处输入图片说明

回答by Logicrat

I'd suggest that you use only one argument set at a time. Each one of the checked lines represents a command line, not a single argument, so put both of your arguments on a single line, as in

我建议您一次只使用一个参数集。每一个选中的行代表一个命令行,而不是一个参数,所以把你的两个参数放在一行上,如

$PROJECT_DIR/detroit.txt $PROJECT_DIR/detroit.out