C++ streambuf - pubseekoff
描述
它用于将内部位置指针设置为相对位置,并使用相同的参数 off、way 和 which 调用受保护的虚拟成员 seekoff。
声明
以下是 std::basic_streambuf::pubseekoff 的声明。
pos_type pubseekoff (off_type off, ios_base::seekdir way,
ios_base::openmode which = ios_base::in | ios_base::out);
参数
off − 它是一个偏移值,相对于方式参数。
返回值
它总是返回修改后的位置指针的新位置值。
异常
Basic guarantee − 如果抛出异常,则流缓冲区处于有效状态。
数据竞争
它修改流缓冲区对象。
示例
在下面的例子中解释了 std::basic_streambuf::pubseekoff。
#include <iostream>
#include <fstream>
int main () {
std::fstream filestr ("sample.txt");
if (filestr) {
std::streambuf* pbuf = filestr.rdbuf();
long size = pbuf->pubseekoff(0,filestr.end);
std::cout << "The file size is " << size << " characters.\n";
filestr.close();
}
return 0;
}

