C++获取文件长度

ifstream fin("example.txt", ios::binary);
fin.seekg(0, ios::end);                      // 设置指针到文件流尾部
streampos ps = fin.tellg();                  // 指针距离文件头部的距离,即为文件流大小
fin.seek(0, 0);                              // 指针重回文件流头部
int len = ps;


posted @ 2014-08-26 21:56  bgmind  阅读(1471)  评论(0编辑  收藏  举报