std::basic_filebuf::seekoff
来自cppreference.com
< cpp | io | basic filebuf
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
protected: virtual pos_type seekoff( off_type off, |
||
重新定位文件指针,如果可能的话,完全
off
字符开始,结束,或当前位置的文件(取决于way
.原文:
Repositions the file pointer, if possible, to the position that corresponds to exactly
off
characters from beginning, end, or current position of the file (depending on the value of way
.如果相关的文件是不公开(is_open()==false,失败的价值对应的位置立即.
原文:
If the associated file is not open (is_open()==false, fails immediately.
如果多字节字符编码状态而定(codecvt::encoding()返回-1)或可变长度(
codecvt::encoding()
返回0),和偏移off
是不是0,立即失败:此功能不能确定对应的字节数off
个字符原文:
If the multibyte character encoding is state-dependent (codecvt::encoding() returned -1) or variable-length (
codecvt::encoding()
returned 0) and the offset off
is not 0, fails immediately: this function cannot determine the number of bytes that correspond to off
characters.way
是不std::basic_ios::cur或偏移off
是不0,和最反感操作这filebuf对象输出(,无论是认沽缓冲区是不是空的,或者最近调用的函数overflow()
),然后调用std::codecvt::unshift来确定必要的不印字序列,以及该序列写入到该文件通过调用overflow()
.原文:
If
way
is not std::basic_ios::cur or the offset off
is not 0, and the most resent operation done on this filebuf object was output (that is, either the put buffer is not empty, or the most recently called function was overflow()
), then calls std::codecvt::unshift to determine the unshift sequence necessary, and writes that sequence to the file by calling overflow()
.,然后将参数转换
way
到如下类型whence
值int:原文:
Then converts the argument
way
to a value whence
of type int as follows: 值的
way |
value of whence
|
std::basic_ios::beg | SEEK_SET |
std::basic_ios::end | SEEK_END |
std::basic_ios::cur | SEEK_CUR |
,然后,如果字符编码是固定宽度(
codecvt::encoding()
返回一些的正数width
,移动文件指针仿佛被std::fseek(file, width*off, whence).原文:
Then, if the character encoding is fixed-width (
codecvt::encoding()
returns some positive number width
, moves the file pointer as if by std::fseek(file, width*off, whence).,否则,移动文件指针,如果std::fseek(file, 0, whence)
原文:
Otherwise, moves the file pointer as if by std::fseek(file, 0, whence).
openmode
参数,需要通过基类的函数签名,通常被忽略,因为std::basic_filebuf
中只有一个文件的位置.原文:
The
openmode
argument, required by the base class function signature, is usually ignored, because std::basic_filebuf
maintains only one file position.目录 |
[编辑] 参数
off | - | 相对位置设置位置指示器.
原文: relative position to set the position indicator to. | ||||||||||||||||
dir | - | 定义应用的相对偏移量的基础地位。它可以是以下常量之一:
| ||||||||||||||||
which | - |
[编辑] 返回值
一个新构造的对象的类型pos_type生成的文件存储位置,或在失败的pos_type(off_type(-1)).
原文:
A newly constructed object of type pos_type which stores the resulting file position, or pos_type(off_type(-1)) on failure.
[编辑] 注释
seekoff()
被称为std::basic_streambuf::pubseekoff,这就是所谓的std::basic_istream::seekg, std::basic_ostream::seekp,std::basic_istream::tellg,std::basic_ostream::tellp原文:
seekoff()
is called by std::basic_streambuf::pubseekoff, which is called by std::basic_istream::seekg, std::basic_ostream::seekp, std::basic_istream::tellg, and std::basic_ostream::tellp[编辑] 示例
#include <iostream> #include <fstream> #include <locale> int main() { // prepare a 10-byte file holding 4 characters in UTF8 std::ofstream("text.txt") << u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"; // open using a non-converting encoding std::ifstream f1("text.txt"); std::cout << "f1's locale's encoding() returns " << std::use_facet<std::codecvt<char, char, std::mbstate_t>>(f1.getloc()).encoding() << '\n' << "pubseekoff(3, beg) returns " << f1.rdbuf()->pubseekoff(3, std::ios_base::beg) << '\n' << "pubseekoff(0, end) returns " << f1.rdbuf()->pubseekoff(0, std::ios_base::end) << '\n';; // open using UTF-8 std::wifstream f2("text.txt"); f2.imbue(std::locale("en_US.UTF-8")); std::cout << "f2's locale's encoding() returns " << std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(f2.getloc()).encoding() << '\n' << "pubseekoff(3, beg) returns " << f2.rdbuf()->pubseekoff(3, std::ios_base::beg) << '\n' << "pubseekoff(0, end) returns " << f2.rdbuf()->pubseekoff(0, std::ios_base::end) << '\n'; }
输出:
f1's locale's encoding() returns 1 pubseekoff(3, beg) returns 3 pubseekoff(0, end) returns 10 f2's locale's encoding() returns 0 pubseekoff(3, beg) returns -1 pubseekoff(0, end) returns 10
[编辑] 另请参阅
调用seekoff() (公共成员函数of std::basic_streambuf )
| |
[虚]</div></div>
|
重新定位文件的位置,使用绝对寻址 原文: repositions the file position, using absolute addressing (虚拟保护成员函数) |
在一个文件中的文件位置指示符移动到特定的位置 原文: moves the file position indicator to a specific location in a file (函数) |