pubseekpos
描述 (Description)
它用于将内部位置指针设置为绝对位置,并使用相同的参数pos和which调用受保护的虚拟成员seekpos。
声明 (Declaration)
以下是std :: basic_streambuf :: pubseekpos的声明。
pos_type pubseekpos (pos_type pos, ios_base::openmode which = ios_base::in | ios_base::out);
参数 (Parameters)
off - 它是位置指针的新绝对位置。
返回值 (Return Value)
它返回修改后的位置指针的新位置值。
异常 (Exceptions)
Basic guarantee - 如果抛出异常,则流缓冲区处于有效状态。
数据竞争 (Data races)
它修改了流缓冲区对象。
例子 (Example)
在下面的例子中解释了std :: basic_streambuf :: pubseekpos。
#include <iostream>
#include <fstream>
int main () {
std::fstream filestr ("test.txt");
if (filestr) {
std::streambuf* pbuf = filestr.rdbuf();
long size = pbuf->pubseekoff(0,filestr.end);
if (size>20) {
char buffer[11];
pbuf->pubseekpos(10);
pbuf->sgetn (buffer,10);
buffer[10]=0;
std::cout << buffer << '\n';
}
filestr.close();
}
return 0;
}