How to Pass Command-Line Arguments in Xcode - c++

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.
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.
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.)
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.

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

Related

Is it possible to change constexpr-ops-limit inside the source file?

I want to change constexpr-ops-limit to a bigger number. I know that it is possible with -fconstexpr-ops-limit= as a command line argument, but I have no possibility to change arguments because I submit my code to a system that runs it automatically. I wonder if there are any pragmas in GCC or VC++ that will match my needs.
Is there any way to do it? Thank you in advance.

Creating and running a file with command line arguments

I am very new to linux and apologize if my descriptions are not savvy. I will try to be relevantly detailed.
Currently I am working on a terminal using Fedora, and my goal is to create a smaller data set to run a program. I was given an example, and my mentor said that to run the program all I had to do was type "./filename" into the console.
filename has command line arguments as follows: "./main ./textfile1 ./textfile2" Basically, each argument is separated by a space.
I tried recreating this document with similar format, but I am not sure what to save it as, nor does it work when I try running it the same way as the file with a larger data set.
Also, filename is bold in the terminal, whereas the document I created it is not. I'm not sure if this helps at all, but it is a difference I noticed.
Any help would be appreciated.
You need to set the execute bit on your file.
chmod +x filename
Make sure you compile the program first (in case you haven't. I use the g++ compiler typically) and then use the ./filename like your instructor said, but do not put "./" in front of the arguments. Just write it as "./filename textfile1.txt textfile2.txt"

Program arguments text box content in codeblocks 10.05 is not visible

Duplicate : The program arguments text box in codeblocks 10.05 is not visible
I want to debug code which takes command line arguments in C++ using Codeblock IDE.I googled and read that "Project-> Set program's aregumnets" can be use to pass the command line arguments. But when I choose that option the textbox is not editable. Please refer the snapshot below for your kind reference.
Any thoughts on on how to fix this.
Edit:
I am on Ubuntu.
I am able to tab in Program arguments but unable to increase the size of text box.Even maximising the window is not doing any help. I can see that I am able to type.
Reinstalling did not help.
I found this link
http://ubuntuforums.org/showthread.php?t=1906791
which talks about hacking "I can work round by hacking the project.cbp file and adding a line but this is messy."
Can someone please elaborate how this workaround might work for me. Thanks.
I find the solution here I don't know how to use Project->Set programs' arguments to provide arguments to.
Basically, what you need to do is to substitute select_target.xrc file in /usr/share/codeblocks/manager_resources.zip with the one in the attached file select_target.zip. The attached file can be only available when you log on the forum.

UniversalindentGUI "(STDERR):Cannot find file indentinput.cpp" Error

I wanted to know if anyone have used UniversalindentGUI.
I am trying to use and when run it get the following error.
There is no proper documentation or tutorial how to use it, if any one have used it please help me.
Indenter returned with exit code: 1
Indent console output was:
(STDOUT):
(STDERR):Cannot find file indentinput.cpp
Callstring was:
"/Users/rbang/Desktop/Tools/UniversalIndentGUI_macx/indenters/astyle"
indentinput.cpp
--options="/Users/rbang/Desktop/Tools/UniversalIndentGUI_macx/temp/.astylerc"
Open up indenters/uigui_astyle.ini in the directory where UniversalIndentGUI is installed and find the following properties:
inputFileName=indentinput
inputFileParameter=
outputFileName=indentinput
outputFileParameter=none
Change them to:
inputFileName=
inputFileParameter=stdin
outputFileName=
outputFileParameter=stdout
Voila!
I experienced the same problem, however if you switch to a different indenter in the pull down menu at the top of the ui(just below the text "Indenter Settings" and use a different indenter(i am using Uncrustify(C, C++, C#, Objective-C) it functions. I suspect it has to do with the fact that all the indenters may not be bundled with the download BUT uncrustify is. Most of the ones I tried have this issue, but the only one I care about is uncrustify.

C++ Passing Options To Executable

How do you pass options to an executable? Is there an easier way than making the options boolean arguments?
EDIT: The last two answers have suggested using arguments. I know I can code a workable solution like that, but I'd rather have them be options.
EDIT2: Per requests for clarification, I'll use this simple example:
It's fairly easy to handle arguments because they automatically get parsed into an array.
./printfile file.txt 1000
If I want to know what the name of the file the user wants to print, I access it via argv[1].
Now about how this situation:
./printfile file.txt 1000 --nolinebreaks
The user wants to print the file with no line breaks. This is not required for the program to be able to run (as the filename and number of lines to print are), but the user has the option of using if if s/he would like. Now I could do this using:
./printfile file.txt 1000 true
The usage prompt would inform the user that the third argument is used to determine whether to print the file with line breaks or not. However, this seems rather clumsy.
Command-line arguments is the way to go. You may want to consider using Boost.ProgramOptions to simplify this task.
You seem to think that there is some fundamental difference between "options" that start with "--" and "arguments" that don't. The only difference is in how you parse them.
It might be worth your time to look at GNU's getopt()/getopt_long() option parser. It supports passing arguments with options such as --number-of-line-breaks 47.
I use two methods for passing information:
1/ The use of command line arguments, which are made easier to handle with specific libraries such as getargs.
2/ As environment variables, using getenv.
Pax has the right idea here.
If you need more thorough two-way communication, open the process with pipes and send stuff to stdin/listen on stdout.
You can also use Window's PostMessage() function. This is very handy if the executable you want to send the options to is already running. I can post some example code if you are interested in this technique.
The question isn't blazingly clear as to the context and just what you are trying to do - you mean running an executable from within a C++ program? There are several standard C library functions with names like execl(), execv(), execve(), ... that take the options as strings or pointer to an array of strings. There's also system() which takes a string containing whatever you'd be typing at a bash prompt, options and all.
I like the popt library. It is C, but works fine from C++ as well.
It doesn't appear to be cross-platform though. I found that out when I had to hack out my own API-compatible version of it for a Windows port of some Linux software.
You can put options in a .ini file and use the GetPrivateProfileXXX API's to create a class that can read the type of program options you're looking for from the .ini.
You can also create an interactive shell for your app to change certain settings real-time.
EDIT:
From your edits, can't you just parse each option looking for special keywords associated with that option that are "optional"?