1. Progressive read-In
void readtxt (string file) { ifstream infile; Infile.open (File.data ()); // assert (Infile.is_open ()); // string s; while (Getline (infile,s)) { cout<<s<<endl; } Infile.close (); // }
2. Read-by-character (ignore spaces and carriage returns)
void readtxt (string file)
Infile.open (File.data ()); // connect the file stream object to the file assert ( Infile.is_open ()); // char C; while (!infile >> C;
cout<<c<<endl; } Infile.close (); // }
3. Read in characters (including spaces and carriage returns)
void readtxt (string file) {Ifstream infile; Infile.open (File.data ()); // connect the file stream object to the file assert ( Infile.is_open ()); // char C; infile >> NOSKIPWS;
while (! Infile.eof ()) { infile>>C; cout<<c<<endl; } Infile.close (); // }
Note : The required header files
#include <iostream><fstream><cassert><string >
C + + Read TXT file