tellg用法
来源:互联网 发布:起诉淘宝网胜诉案例 编辑:程序博客网 时间:2024/04/28 19:19
tellg
tellg()(和tellp() ) 是C++文件流操作中获得流指针的函数。 所有输入/输出流对象(i/o streams objects)都有至少一个流指针: · ifstream, 类似istream, 有一个被称为get pointer 的指针,指向下一个将被读取的 元素。 · ofstream, 类似ostream, 有一个指针put pointer ,指向写入下一个元素的位置。 · fstream, 类似iostream, 同时继承了get 和put 我们可以通过使用以下成员函数来读出或配置这些指向流中读写位置的流指针: tellg() 和tellp() 这两个成员函数不用传入参数,返回pos_type 类型的值(根据ANSI-C++ 标准) , 就是一个整数,代表当前get 流指针的位置(用tellg) 或put 流指针的位置(用 tellp).而且不要对tellg 或tellp 的返回值进行修改。 tellg(io)函数 函数定义 pos_type tellg(); 函数说明 用于输入流,返回流中‘get’指针当前的位置。 函数示例 ifstream file; char c; streamoff i; file.open("basic_istream_tellg.txt");//文件内容:0123456789 i = file.tellg(); file >> c; cout << c << " " << i << endl; 输出: 0 0 tellp(io)函数 函数定义 pos_type tellp(); 函数说明 用于输出流,返回当前流中‘put’指针的位置。 函数示例 string str(“test”); ofstream fout(“e:\\output.txt”); int k; for(k = 0; k < str.length(); k++) { cout<<”File point:”<<fout.tellp(); fout.put(str[k]); cout <<” “<<str[k]<<endl; } fout.close(); 输出: File point:0 t File point:1 e File point:2 s File point:3 t 下例使用这些函数来获得一个二进制文件的大小: // obtaining file size #include <iostream.h> #include <fstream.h> const char * filename = "example.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; }
- seekg()与tellg()用法
- seekg()与tellg()用法详解
- tellg用法
- tellg
- seekg() 与 tellg() 的用法及功能
- seekg()/seekp()与tellg()/tellp()的用法详解
- seekg()/seekp()与tellg()/tellp()的用法详解 .
- seekg()/seekp()与tellg()/tellp()的用法详解
- seekg()/seekp()与tellg()/tellp()的用法详解
- seekg()/seekp()与tellg()/tellp()的用法详解
- seekg()/seekp()与tellg()/tellp()的用法详解
- seekg()/seekp()与tellg()/tellp()的用法详解
- 6.17 阅读程序 理解seekg() tellg()的用法
- seekg()/seekp()与tellg()/tellp()的用法详解
- C++流 rdbuf()以及seekg()/seekp()与tellg()/tellp()的用法详解
- C++流 rdbuf()以及seekg()/seekp()与tellg()/tellp()的用法详解
- 第14周-阅读项目3-seekg()、tellg()等函数的功能及其用法
- C++:fstream类中seekg()/seekp()与tellg()/tellp()的用法详解
- 阿里巴巴2011年校招试题
- 2012黑客工具包.zip
- 广东一伙劫匪在抢劫银行时说了一句至理名言!!震惊了许多人
- ExtJS Store 方法以及属性介绍
- Automatic Reference Counting
- tellg用法
- 第九天 T—SQL小结续以及数据库的一些其他
- GStreamer App开发 (一)
- Ubuntu(Linux)中文支持,包括文本模式中文化
- 百度2012实习生校园招聘笔试题
- 关于CF的TP禁止双机调试的一点记录
- Android Tips
- 关于联想thinkpad e40 安装xp之后开启AHCI蓝屏的解决办法
- zoj 2562