我需要编写一个程序来读取文件中的某些字符。例如:所有字符从头到尾或倒序排列。如何显示所有字符而不是一个字符?
//This program reads a file from beg to end, end to beg, beg to 4th position,
//8th to 15th position, end to 3rd position, and 22nd to end
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char letter; //holds the character
fstream file("alphabet.txt", ios::in);
file.seekg(5L, ios::beg);
file.get(letter);
cout << "Beginning to the 4th letter: " << letter << endl;
file.seekg(-22L, ios::end);
file.get(letter);
cout << "21st letter to the end: " << letter << endl;
file.close();
system("pause");
return 0;
}