File as stdin in C on the command line in visual studio

When I write a C program and compile it using a standalone compiler such as MinGW, I can write "myprogram.exe <test.txt" and the standard input is test.txt.

How can I do this in Visual Studio 2010? I know the "Command Arguments" in the project properties, and then the debugger, but I do not know what to enter there. Is this just the input file path or something else?

+4
source share
5 answers

Visual Studio supports this use case. For your C ++ project, go to properties, configuration properties, debugging, and in command arguments like "<test.txt".

+8
source

You cannot do this directly in Visual Studio. I / O redirection is a feature of the shell, not VS. You can open a command prompt, go to the directory where the executable is located, and run the command:

myprogram.exe < test.txt 

(suppose test.txt is also in this directory if you cannot always use the full pathnames).

Refresh . Perhaps you can do what you want by asking VS to run a command prompt for you and running the program. Under "Configuration Properties" | Debugging, replace the one in the Command field (usually $ (TargetPath)):

 cmd.exe /c "$(TargetPath)" < source-file 

Leave the command arguments blank. I have never tried this. Perhaps this will not work.

+2
source

Go to your project properties and in the "Configuration Properties> Debugging" section, in the "Command Arguments" field, enter the following: < "$(TargetDir)\input.txt"

Note:

  • $(TargetDir) expands to the Debug folder of your project, so make sure it has input.txt. You can put any path here, but make sure it is absolute.
  • Be sure to use double quotes, otherwise you will receive an error message if your path contains spaces.

(using Visual Studio 2013 with C ++)

+2
source

This is a command line shell function, not a compiler. You can do just that if you use msys bash instead of using the standard (crappy) Windows DOS shell.

0
source

For a project in a visual studio, right-click on the project and select "Properties." In the properties window, you can enter the absolute path to the physical file that you want to use as input.

Else You can run the application from the Visual Studio console

Start-> Programs-> Microsoft Visual Studio 2xxx-> Command Line Visual Studio

Program:

  class Program { static void Main(string[] args) { if (args.Length > 0) { foreach (var item in args) { Console.WriteLine("{0}", item); } } } } 

Visual studio 2010Console Application Argument settings

-1
source

All Articles