'Accessing a file in C++ code using the "./program < file" command line argument

I'm sure this is an extremely simple issue - I've been searching for an answer everywhere but I think my problem is that I don't know the right terminology to use while searching.

I'm currently working on an assignment for a class using C++. Essentially, I need to read a file into a C++ program, do some stuff, and create an output - I've done all of this already. I was accessing the file by just using

fstream file;
file.open("file.txt");'

in the .cc file itself, and that was working fine. However, I just saw in the instructions for this assignment that this is not how the instructor will be testing the program - instead, they will simply run my executable like this: ./program < file.txt

I'm familiar with using command line arguments within C++ programs, and I'm able to make the program work no problem when running ./program file.txt (just passing the file as an argument), but I can't figure out how to do it the way the instructor is asking for. Worse off, I can't figure out how to actually search for the answer since I don't know the correct terminology yet (I'm simultaneously only in the first few weeks of my UNIX class).

Is anyone able to help point me in the right direction? Thanks a bunch!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source