C++如何获得文件大小(3)

//利用文件指针实现
//假设文件file.txt存在,且在当前目录下
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
    ifstream in("file.txt");
    in.seekg(0, ios::end);      //设置文件指针到文件流的尾部
    streampos ps = in.tellg();  //读取文件指针的位置
    cout << "File size: " << ps << endl;
    in.close();                 //关闭文件流
    return 0;
}
posted @ 2006-02-25 14:03  rousya  阅读(138)  评论(0)    收藏  举报