Xcode won't pass arguments to C++ executable - c++

I'm attempting to debug a C++ project using Xcode. My program looks for input through stdin like so:
string line;
getline(cin, line);
I have an input file called input.txt that I normally pass into the executable like so:
./verti < input.txt
In order to accomplish the same thing while debugging in Xcode, I've added an argument to be passed on launch by Product > Scheme > Edit Scheme... > Run > Arguments with a value of < input.txt. The text file is located in the same working directory as the executable, yet when I build/run the program, the text file isn't being passed in. The program just waits for input that it should receive. If you guys could lend any insight, that'd be really helpful.
I'm running Xcode 6.3.1 on OS X 10.10.1.

The < is actually interpreted by the shell (when using a terminal and the command line). In case of Xcode there is no shell involved, so you can't pipe input to stdin.
You have to open the file (in argv[1]) in your process and use the file descriptor instead of stdin.

Related

How do I use a text file for stdin input in DEV C++ IDE?

I am trying to use a .txt file for my stdin in a c++ program. Essentially, I am just trying to find where in this IDE (Dev C++) I would be able to specify the file I want to use for program input.
I thought that I would be able to read file input here:
But this doesn't seem to be working. I have tried with a space between the 1 and the file name and with quotes around the file name.
I know my program allows for the file to be read properly because when running it in the command line it outputs the first line of the stdin file, test01.txt.
The command I am using to run the program in cmd line is: ./prog 1 < test01.txt where 1 is a case number for a switch statement and test01.txt is input used by that switch statement.
How would I mimic this command line call in Dev C++ IDE? The test01.txt file is part of my project files...

Qtcreator get stdin from a file instead of terminal

I am making a program that reads from stdin.
I want to debug the program in qtcreator but I can't find a way of providing input except using the terminal. Which is not very practical because my input is a big file with a lot of lines.
I tried going to the run options of qtcreator and insert the following in the Command Line Arguments: < filename
But Qtcreator gave me an error in the application output:
14:26:54: Debugging complex shell commands in a terminal is currently not supported.
Is there no way of providing a file as stdin in qtcreator?

Xcode 8.3: Run target with input from file

I wrote a simple C++ program that requires some input to run. In the terminal I simply run in ./myProgram < fileWithData.txt. However I could not figure out how to specify and input file for the target executed in Xcode. I used the command line project. Of course I could use a different target, for example run Terminal.app and then pass it the executable with the input file but then I can no longer debug it.
This question: Cannot get lldb to read file input explains how to set the input path in lldb, but I could not find a way to specify lldb commands that are executed before the process is started.
I don't think there's a way to do this entirely from within Xcode. However if you set the Run Scheme in Xcode to the launch mode "Wait for executable to be launched," hit run, and then run your program from Terminal.app with the appropriate piping, the Xcode-embedded lldb will connect to it.

How do redirect STDOUT out of XCode compiled Command Line executable?

I have a C++ program that writes to stdout that I am trying to compile into a command line utility in XCode. I need the program compiled into a release build (which it seems, XCode calls an Archive - go figure), not run it as debug.
I basically want to pipe the output of my program into a textfile like this
MyProgram > TextFile.txt
I can compile the program into a command line and run it like this via a Bash shell like this:
Open MyProgram
This spawns a new process (not what I want). However, I could live with that if this worked:
Open MyProgram > TextFile.txt
...But it doesnt :-(. If I try to just run MyProgram directly from Bash, I get the error: -bash: MyProgram: command not found.
What am I doing wrong? How can I compile my command line tool to NOT require the Open command under Mac OSX?
Thanks for any help you can provide. I am picking up C++ on the Mac platform and I am beginning to find it quite it a bit more troublesome than Visual Studio. Does it ever get less painful to work with? :-)
Make your project a Command Line Tool. This will make it so you can run it from the command line directly.
Run it by typing ./MyProgram or ./MyProgram > TextFile.txt not open MyProgram.

How to do input redirection using Visual Studio 2010?

I have an input.txt file. In that file, there are a series of pairs such as:
interactive 300
cpu 200
disk 400
real-time 500
tty 300
disk 200
While making the program I had opened a file called input.txt and used the fstream to read in all of these pairs. Something like
infile >> string1 >> int1
my question now is, how do I get visual studios to do input redirection with the input.txt file. I've gone and changed all my instances of infile to cin, as I believe i'm supposed to do. I went into Project > Properties > Debugging > Command arguments and typing in :
< input.txt
But that only works when I run it from within visual Studios. When I compile it, go to the folder where the exe is, place the input file in that folder and run the exe, nothing happens. I just get a cmd window with a blinking _ .
Thanks for the help to anyone that does :)
It is waiting for you to type something. You have to start it by typing 'yourapp < input.txt' at the command line. Or you can type in the lines that are now in the file, finish with Ctrl+Z.
The things you type into command arguments in Visual Studio only work when you run the executable through Visual Studio, using the Run command. Those settings are not saved with the executable at all.
You have to provide the < input.txt at a command window. If you'd rather click on an icon to launch the program instead, you can put the command into a batch (.bat) file and use a link to the batch file.