c++ fstream中seekg()和seekp()的用法

來源:互聯網
上載者:User

先說一下C語言中fseek()的功能:

函數原型:int fseek(FILE *fp, LONG offset, int origin)

參數含義:fp 檔案指標 offset 相對於origin規定的位移位置量 origin 指標移動的起始位置,可設定為以下三種情況: SEEK_SET 檔案開始位置 SEEK_CUR 檔案當前位置 SEEK_END 檔案結束位置

C++中seep()和seekg()函數功能

seekp:設定輸出檔案流的檔案流指標位置
seekg:設定輸入檔案流的檔案流指標位置
函數原型:
ostream& seekp( streampos pos );
ostream& seekp( streamoff off, ios::seek_dir dir );
istream& seekg( streampos pos );
istream& seekg( streamoff off, ios::seek_dir dir );
函數參數
pos:新的檔案流指標位置值
off:需要位移的值
dir:搜尋的起始位置
dir參數用於對檔案流指標的定位操作上,代表搜尋的起始位置
在ios中定義的枚舉類型:
enum seek_dir {beg, cur, end};
每個枚舉常量的含義:
ios::beg:檔案流的起始位置
ios::cur:檔案流的當前位置
ios::end:檔案流的結束位置

 

轉載至http://blog.sina.com.cn/s/blog_679f85d40100mysi.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.