C++ ifstream Reads the TXT file backwards, printing each character
#include <fstream.h> #include <stdlib.h> #include <stdio.h> ifstream fp;// w w w .java2 s .c o m void main() { int ctr; // Steps through the 26 letters in the file. char in_char; fp.open("ALPH.TXT", ios::in); if (!fp) { cout << "\n*** Error opening file ***\n"; exit(0); } fp.seekg(-1L, SEEK_END); // Point to last byte in the file. for (ctr = 0; ctr < 26; ctr++) { fp >> in_char; fp.seekg(-2L, SEEK_CUR); cout << in_char; } fp.close(); return; }