pubseekoff
描述 (Description)
它用于将内部位置指针设置为相对位置,并使用相同的参数off,way和which调用受保护的虚拟成员seekoff。
声明 (Declaration)
以下是std :: basic_streambuf :: pubseekoff的声明。
pos_type pubseekoff (off_type off, ios_base::seekdir way,
ios_base::openmode which = ios_base::in | ios_base::out);
参数 (Parameters)
off - 相对于way参数,它是一个偏移值。
返回值 (Return Value)
它总是返回修改后的位置指针的新位置值。
异常 (Exceptions)
Basic guarantee - 如果抛出异常,则流缓冲区处于有效状态。
数据竞争 (Data races)
它修改了流缓冲区对象。
例子 (Example)
在下面的例子中解释了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;
}