Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ add input to stdin from the program?

Tags:

c++

c

input

stdin

Is that even possible ?

Lets say that the code has a lot of scanf lines. Instead of manually running and adding values by hand when debugging, is it possible to "feed" stdin with data so that when the scanf starts reading, it will read the inputted data without any need to interact with the terminal.

like image 526
Milan Avatar asked Dec 02 '22 07:12

Milan


1 Answers

Put the test lines into a file, and run the program like this:

myprogram < mytestlines.txt

Better than hacking your program to somehow do that itself.

When you're debugging the code, you can set up the debugger to run it with that command line.

like image 50
RichieHindle Avatar answered Dec 14 '22 23:12

RichieHindle