这个程序代码自己改了下,还是运行不了啊,求大神!!!!
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
class TxtReader
{
private:
ifstream txtfile;
static const int linesize;
static const int rowsize;
vector<fstream::streampos>screenpos;
public:
TxtReader(string name);
void LastScreen();
void NextScreen();
void ShowContent();
~TxtReader();
};
const int TxtReader::linesize = 22; //一屏22行
const int TxtReader::rowsize = 70; //一行70个字符
TxtReader::TxtReader(string name)
{
txtfile.open(name);
if(!txtfile)
{
cout << "Open file failed!" << endl;
return;
}
screenpos.push_back(txtfile.tellg());
ShowContent();
}
TxtReader::~TxtReader()
{
txtfile.close();
}
void TxtReader::ShowContent()
{
char tmp[rowsize+1];
int line = 0;
while((!txtfile.eof())&&(line!=linesize))
{
txtfile.getline(tmp, rowsize+1);
line += 1;
cout << tmp << endl;
}
}
void TxtReader::NextScreen()
{
if(txtfile.eof())
return;
screenpos.push_back(txtfile.tellg());
ShowContent();
}
void TxtReader::LastScreen()
{
if(screenpos.size() == 1)
return;
txtfile.seekg(screenpos.back());
screenpos.pop_back();
ShowContent();
}
int main()
{
cout << "Input the file name to open:" << endl;
string filename;
cin >> filename;
TxtReader reader(filename);
char control;
while(cin >> control)
{
if(control == 'n')
reader.NextScreen();
if(control == 'p')
reader.LastScreen();
if(control == 'q')
break;
}
}