歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> C++ read(),write() ,seekg(),tellg()

C++ read(),write() ,seekg(),tellg()

日期:2017/3/1 10:07:24   编辑:Linux編程

istream &seekg(streamoff offset,seek_dir origin);

pos_type tellg() 返回流置針所在的位置,返回值為整數

從文件origin位置開始移動offset個字節

讀寫數據塊

要讀寫二進制數據塊,使用成員函數read()和write()成員函數,它們原型如下:

read(unsigned char *buf,int num);

write(const unsigned char *buf,int num);

read()從文件中讀取 num 個字符到 buf 指向的緩存中,如果在還未讀入 num 個字符時就到了文件尾,可以用成員函數 int gcount()來取得實際讀取的字符數;而 write() 從buf 指向的緩存寫 num 個字符到文件中,值得注意的是緩存的類型是 unsigned char *,有時可能需要類型轉換。

Copyright © Linux教程網 All Rights Reserved