小编adl*_*r25的帖子

打印出文件的最后10行

我想要打印出文本文件的最后10行.使用这个程序我已经能够读取整个文本文件,但我无法弄清楚如何在保存文本文件的情况下编写数组,任何帮助?

// Textfile output
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;

int main() {
    int i=1;
    char zeile[250], file[50];
    cout << "filename:" << flush;
    cin.get(file,50);                          ///// (1)
    ifstream eingabe(datei , ios::in);          /////(2)
    if (eingabe.good() ) {                       /////(3)           
       eingabe.seekg(0L,ios::end);               ////(4)
       cout << "file:"<< file << "\t"
            << eingabe.tellg() << " Bytes"       ////(5)
            << endl;
       for (int j=0; j<80;j++)
           cout << "_";
           cout << endl;
       eingabe.seekg(0L, ios::beg);              ////(6)
       while (!eingabe.eof() ){                  ///(7)
             eingabe.getline(zeile,250);         ///(8)
             cout << setw(2) << i++
                  << ":" << zeile …
Run Code Online (Sandbox Code Playgroud)

c++ cout file tail

4
推荐指数
1
解决办法
5693
查看次数

标签 统计

c++ ×1

cout ×1

file ×1

tail ×1