The following code is an example of opening an input file and printing to the screen. Using input and output files can improve functionality of a user’s code by allowing for appending and truncating of files. Input files are often useful in programs that are not run by a user but rather predetermined information that needs to be accessed quickly. First use the #include statements
and followed by using namespace std; .
Inside the main function declare a string and ifstream. In this if-else statement the file is checked, IF it is open a while loop executes. while(! InputFile.eof()) translates to while not end of input file get information from file and print to screen.
No comments:
Post a Comment