Epsilon Vector
Epsilon Vector

Reputation: 1507

Reading input from file in Visual Studio 2008

Is there a way to simulate: yourprogram < inputFile.txt in Visual Studio 2008?

Upvotes: 5

Views: 27293

Answers (7)

Prafull Singh
Prafull Singh

Reputation: 1

Keep your test data input file in Project working directory where *.cpp file is present Right click on Project->properties->Configuration properties ->debugging

In Debugging, click on command Arguments tab and add following line

< Your_project_directory_path\input.txt

Upvotes: 0

Lucas
Lucas

Reputation: 1

I just discover how to make it work with Ctrl + F5. Just put the inputFile.txt on the same folder of your .exe of the project

Upvotes: 0

user139232
user139232

Reputation:

  • In the menu at the top click Project, then Properties (bottom option)
  • In the " Property Pages" window, expand "Configuration Properties", on the left
  • choose "Debugging", on the left
  • in the "Command Arguments" field, on the right, type "< inputFile.txt"

When you do this, notice at the top of the Property Pages window you have selected the current Configuration and Platform. So if you change configuration(e.g. from "debug" to "release"), suddenly these options don't apply, and you'll have to go back to this properties window to set these configs for that configuration/platform.

Also, this only seems to apply when you run using "Start without Debugging" (F5) and not when using "Start Debugging" (Ctrl + F5). I would think there's some way to have an input file work w/ Ctrl+F5, but I haven't found it yet.

Upvotes: 6

HananBar
HananBar

Reputation:

I can give you an answer for C++ (at least) in project properties: Configuration Properties -> Debugging in Command arguments: inputfile.txt and make sure the working directory is the same as the one the file is in

Upvotes: 0

Eoin Campbell
Eoin Campbell

Reputation: 44268

When you've developed your application (e.g. a ConsoleApplication) you would normally start this from the Command Line with

ConsoleApplication1.exe < inputfile.txt

The part of the command < inputfile.txt is the command line arguments to your application.

You can set these in your project properties

  • Right click the project file
  • Click properties
  • Click the Debug tab
  • In the Start Options section enter

    < Path/To/inputfile.txt
    

When you next launch your application with the debugger, it will execute your application with these Command line args

Upvotes: 8

Ryan Emerle
Ryan Emerle

Reputation: 15811

Assuming your looking to read from stdin, you should have a glance at OpenStandardInput.

Upvotes: 0

Konrad Rudolph
Konrad Rudolph

Reputation: 545528

Visual Studio is an IDE (= an embellished editor), not a programming language. What language/environment do you use?

The above causes the file inputFile.txt to be streamed into the standard input stream of a program. All languages offer different mechanisms of accessing this stream and reading from it.

Upvotes: 1

Related Questions