第十六周阅读程序-7

来源:互联网 发布:mmd舞蹈动作数据 编辑:程序博客网 时间:2024/04/30 10:28
/*copyright(c)2016.烟台大学计算机学院  * All rights reserved,  * 文件名称:text.Cpp  * 作者:刘涛  * 完成日期:2016年6月11日  * 版本号:vc++6.0  * 问题描述:阅读程序  */  #include<iostream>#include <fstream>using namespace std;const char * filename = "a.txt";int main (){    long l,m;    ifstream file (filename, ios::in|ios::binary);    l = file.tellg();    file.seekg (0, ios::end);    m = file.tellg();    file.close();    cout << "size of " << filename;    cout << " is " << (m-l) << " bytes.\n";    return 0;}

运行结果;

C++中seekg函数的功能是:设置输入文件流的文件流指针位置。第一个参数是指偏移的位置,第二个参量指新的文件流指针位置值;

tellg()用于输入流,返回流中指指针当前的位置。

程序作用就是检查a.txt中的字节数。


0 0
原创粉丝点击