Doubt regarding USACO Training input

I was learning from the USACO Portal when I came across the following template for submitting solutions., in C++. It was like this.

I’m confused. It uses fin and fout to input a and b. I’ve been using cin and cout till now, so if I use the USACO training pages, am I supposed to uses fout in place of cout always?

Well, fout and fin are used to define input and output from a file. Really you could use anything as they are user defined names.

#include <fstream>

ifstream fin (""); //you could use anything instead of fin...
// It is user defined, use whatever you want.
// ifstream cfin ("") would get the job done in the same
//manner excpet now you would write cfin >> a >> b;
ofstream fout ("filename.out") ;

int a, b;
fin >> a >> b;
fout << a+b << "\n"
//This code snippet can be used to read input from and give output to 
// filename.out
1 Like


void usaco(string name = "")
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);

Your main function should look like:

int main()
    // code ...

You can use it normally as well. Don’t keep any argument. For USACO, suppose that the filename is “angrycows”.
Your code should look like

int main()
    // code ...

Thanks a lot ! @therealnishuz @flash_0408 !