How the program reads the file--one character for reading
#include <iostream> #include <fstream> using namespace STD; int main () { char ch; FStream fp ( " a.txt " ); while (! if (Fp.get <<CH; } fp.close (); return 0 ;}
The way the program reads the file--read by line
#include <iostream>#include<fstream>using namespacestd;intMain () {Charline[ -]; FStream FP ("a.txt"); while(!fp.eof ()) {Fp.getline (line, -); cout<<line<<Endl; } fp.close (); return 0;}
How the program reads a file--a word that reads a word
#include <iostream>#include<fstream>using namespacestd;intMain () {Charstr[ -];//string str;FStream FP ("a.txt"); while(!fp.eof ()) {FP>>str; cout<<str; } fp.close (); return 0;}
It is recommended to use line-by-row reading, or a character-by-word reading method. Word-by-phrase reading is not a good solution because it does not read a new line of information,
So if you have a new line in your file, it will not display those new lines, but instead add them to the text that has already been printed. and using Getline () or
Get () will show you the true nature of the file.
How the program reads the file-by character, by line, by word