File Input (And Even Output)
Access data and information stored in various file types
The entire goal of computing and software development can often be boiled down to taking some input, doing any necessary computing or processing, and producing some output, which is hopefully useful for whoever wants it.
There are many ways to receive input in a program or operation: from the command line (terminal), from a remote or other buttons, from a text entry box, from files, and countless others. Writing data to and receiving data from files is very common in real-world software because various file types allow humans to much more easily view and read information (and text files are used for almost every puzzle on this site).
File Input in Your Programs
To read input from files in your own code, you are going to need to identify for your program where the file is located. For small-scale operations like these puzzles, the file (.txt for plain text file) can simply be stored in the same directory (folder) as your code file (which could be .py for Python, .c/.cpp for C/C++, or .java for Java). This way, when you give the file to whatever process your language requires, the filename alone can be sent and the file opener will infer that the file is in the same, or current working, directory as your code file.
Now, this file opener process is different for each language.
Python
For Python, the open() function can be used and it's quite simple to iterate over the lines in the file. Learn more about this process here.
C++
For C++, you need to #include the ifstream class, which allows you to create an input file stream object that can move through the file for you. Including files or classes in C++ means that you are bringing in outside code that will allow you to perform more complicated tasks without writing the code yourself. These are used all the time in development and in this case, you are "including" the standard way of reading text file input in C++ into your program. It is most convenient to use the ">>" operator to bring the next piece of input from the file (excluding whitespace). Learn more about C++'s slightly more complicated process for file input/output here from GeeksForGeeks, here from W3Schools, and even a video here.
Java
In Java, the file input process uses what are called Object Scanners, which are Java's equivalent of an input stream. The Scanner, File, and FileNotFoundException classes must be imported into your program, and then text files can be iterated over and read using the nextLine() function. Learning Java as you take on these puzzles? Learn more about this process here.
Output, Too?
File input is going to be far more important for solving these puzzles, but file output is also an important tool for working with file data. Most languages support processes that are very similar to input for output and writing to files. For example, Python has a write() function like its read(), and C++ has ofstreams, which are Output File Streams and work just like ifstreams, Input File Streams. Learn more about Python writing here, C++ ofstreams here, and Java file output here