visual studio - Imitating standard user input in c++ with command line arguments -
let's have following c++ code
#include <iostream> int main() { int x,y; std::cout << "please enter first input." << std::endl; std::cin>>x; std::cout << "please enter second input." << std::endl; std::cin>>y; std::cout<<x/y<<std::endl; return 0; }
i can compile file command line cl/ehsc sample.cpp
what want display output(s) of program inputs given command line.how can this?
x should it's value first command line argument,
y should it's value second command line argument.
following should work want avoid fiddling visual studio properties etc.
piping input c++ program debug in visual studio
edit: further clarification want use automated system receives input command line , not want modify original code
the accepted answer of "piping input" question linked applies question well. don't have fiddle visual studio properties if use command line window it. open command prompt , 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
Comments
Post a Comment