0

Let's say I have the following C++ Code

#include <iostream>
int main()
{
   int x,y;
   std::cout << "Please enter the first input." << std::endl;
   std::cin>>x;
   std::cout << "Please enter the second input." << std::endl;
   std::cin>>y;
   std::cout<<x/y<<std::endl;
   return 0;
}

I can compile the file from command line with cl/EHsc sample.cpp

what i want to do is to display the output(s) of the program with inputs given from the command line.How can i do this?

x should get it's value from the first command line argument,

y should get it's value from the second command line argument.

Following should work but i want to avoid fiddling with Visual Studio Properties etc.

Piping input into a c++ program to debug in Visual Studio

Edit: Also for further clarification i want to use it as an automated system where it receives the input from the command line and I do not want to modify the original code

Community
  • 1
  • 1
usry
  • 27
  • 1
  • 6

1 Answers1

0

The accepted answer of the "piping input" question you linked to applies to your question as well. You don't have to fiddle with Visual Studio properties if you use a command line window to do it. Just open up a command prompt and type it:

cd c:\path\to\project\debug
sample.exe < my_input.txt

Edit: WhozCraig's suggestion works too:

cd c:\path\to\project\debug
echo 6 2 | sample.exe
Darryl
  • 5,907
  • 1
  • 25
  • 36