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?

@anon21889647
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 ("filename.in"); //you could use anything instead of fin...
// It is user defined, use whatever you want.
// ifstream cfin ("filename.in") 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 filename.in and give output to 
// filename.out
1 Like

No.
Define

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

Your main function should look like:

int main()
{
    usaco();
    // 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()
{
    usaco("angrycows");
    // code ...
}

Thanks a lot ! @therealnishuz @anon11076894 !