C++文件长度

来源:互联网 发布:微信抢号软件 编辑:程序博客网 时间:2024/05/22 05:20

以下程序可以计算TXT文件的长度。

#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int main()

 {
   ifstream fina;
   fina.open("test.txt");
   fina.seekg(0,ios::end);
   int endI = fina.tellg();
   fina.seekg(0,ios::beg);
   int beginI = fina.tellg();
   int size = endI - beginI;               //文件长度

   cout<<size<<endl;

   return 0;

}

0 0