The < file.txt
syntax you're using is essentially simulating keyboard input, i.e., an input stream traditionally known/accessed as std::cin
in C++ or stdin
in C.
More background on that topic: What are the shell's control and redirection operators?
Your code is trying to iterate over command-line arguments, which is neither pulling input from std::cin
, nor is it accessing the input with any awareness that a file is involved.
If you want, or need, to extract data from std::cin
(which is consistent with your <
syntax), check out the following reference with examples of how that's done: std::cin, std::wcin.
If you want to process input as a file, try this reference with example: std::basic_ifstream.
(Note that this latter example deals with a binary file, but you can make appropriate changes for your text file.)