精華區beta NTUBA92 關於我們 聯絡資訊
#include <fstream.h> #include <stdlib.h> const int MAXLENGTH = 31; char filename[MAXLENGTH] = "test.dat"; int main() { char ch; long offset, last; ifstream in_file(filename); if (in_file.fail()) // check for successful open { cout << "\nThe file was not successfully opened" << "\n Please check that the file currently exists" << endl; exit(1); } in_file.seekg(0L,ios::end); // move to the end of the file last = in_file.tellg(); // save the offset of the last character for(offset = 1L; offset <= last; offset++) { in_file.seekg(-offset, ios::end); ch = in_file.get(); cout << ch << " : "; } in_file.close(); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.twbbs.org) ◆ From: ntumcc66.mba.ntu.edu.tw