From 900dd09cd69632a034e98aaa5091ddfd853343ad Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 18 Jun 2020 14:19:44 -0500 Subject: [PATCH] Update Input_Output.md --- content/1_Intro/Input_Output.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/content/1_Intro/Input_Output.md b/content/1_Intro/Input_Output.md index 3b67df4..366e41e 100644 --- a/content/1_Intro/Input_Output.md +++ b/content/1_Intro/Input_Output.md @@ -14,7 +14,7 @@ Demonstrates how to read input and print output for USACO. In CodeForces and CSES, input and output are **standard**, meaning that using the library [\](http://www.cplusplus.com/reference/iostream/) suffices. -However, in USACO, input is read from a file called `problemname.in`, and printing output to a file called `problemname.out`. Note that you'll have to rename the `.in` and `.out` files. You will need the [\](http://www.cplusplus.com/reference/cstdio/) or the [\](http://www.cplusplus.com/reference/fstream/) library. Essentially, replace every instance of the word *template* in the word below with the input/output file name, which should be given in the problem. +However, in USACO, input is read from a file called `problemname.in`, and printing output to a file called `problemname.out`. Note that you'll have to rename the `.in` and `.out` files. You will need the [\](http://www.cplusplus.com/reference/cstdio/) or the [\](http://www.cplusplus.com/reference/fstream/) library. Essentially, replace every instance of the word `problemname` in the word below with the input/output file name, which should be given in the problem. For example, for (this problem)[http://www.usaco.org/index.php?page=viewproblem2&cpid=1035], you would replace `problemname` with `socdist1` to get `socdist1.in` and `socdist1.out`. In order to test a program, create a file called `problemname.in`, and then run the program. The output will be printed to `problemname.out`. @@ -28,12 +28,14 @@ If `` is used: using namespace std; int main() { - freopen("template.in", "r", stdin); - freopen("template.out", "w", stdout); + freopen("problemname.in", "r", stdin); + freopen("problemname.out", "w", stdout); + + // rest of your code ... } ``` -If `` is used (note that if you use ``, you must replace `cin` and `cout` with `fin` and `fout`): +If `` is used (Note that you cannot use C-style I/O (scanf, prinf) with this method): ```cpp #include @@ -41,8 +43,10 @@ If `` is used (note that if you use ``, you must replace `cin` using namespace std; int main() { - ifstream fin("template.in"); - ofstream fout("template.out"); + ifstream cin("problemname.in"); + ofstream cout("problemname.out"); + + // rest of your code ... } ``` @@ -180,4 +184,4 @@ public static void main(String[] args) { pw.println(a + b + c); pw.close(); } -``` \ No newline at end of file +```