I'm currently using C++ and VSCode for competitive programming in USACO. Recently, they changed their input format from file input to inputting data from terminal/stdin, which is slower because I have to paste the input into the terminal every time. Is there a way to just write data to a file and have it inputted into cin every time I run my program?
Asked
Active
Viewed 62 times
0
-
Are you looking for input redirection? Something like `myProgram < myFile.txt`? – Nathan Pierson Jul 03 '22 at 21:23
-
You can make cin read from a file (but you need to undo it before submitting obviously) https://stackoverflow.com/questions/10150468/how-to-redirect-cin-and-cout-to-files – Jerry Jeremiah Jul 03 '22 at 21:42
1 Answers
0
I personally use custom run configuration < input > myoutput && diff myoutput output
with CodeRunner to read input and compare with expected output.
For example in case of C++,
In VSCode's settings.json
, modify the code-runner.executorMap
as below and use Ctrl+Alt+N to run
"code-runner.executorMap": {
...
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt < input > myoutput && diff myoutput output",
...
}
input - input to your program
output - the expected output from your program
myoutput - the actual output of your program.

Manav Chhibber
- 678
- 3
- 16