std::basic_ostream::seekp
来自cppreference.com
< cpp | io | basic ostream
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| basic_ostream& seekp( pos_type pos ); |
(1) | |
| basic_ostream& seekp( off_type off, std::ios_base::seekdir dir); |
(2) | |
设置的输出位置指示器的当前相关的
streambuf对象. Original:
Sets the output position indicator of the current associated
streambuf object. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
首先,构建了一个sentry对象,检查错误,并刷新了tie()'D输出流的流。 (C++11 起)之后
1) Original:
First, constructs a sentry object which checks the stream for errors and flushes the tie()'d output streams. (C++11 起) Afterwards,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
设置输出位置指示器,以绝对的(相对于开头的文件)的值通过调用
2) posrdbuf()->pubseekoff(pos, std::ios_base::out)。如果在调用返回(pos_type)-1,执行setstate(failbit).Original:
sets the output position indicator to absolute (relative to the beginning of the file) value
pos by calling rdbuf()->pubseekoff(pos, std::ios_base::out). If the call returns (pos_type)-1, executes setstate(failbit).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
设置输出位置指示器,以抵消
off相对于dir通过调用rdbuf()->pubseekoff(off, dir, std::ios_base::out)。不报告错误.Original:
sets the output position indicator to offset
off relative to dir by calling rdbuf()->pubseekoff(off, dir, std::ios_base::out). Does not report errors.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| pos | - | 绝对位置设置输出位置指示器.
Original: absolute position to set the output position indicator to. The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | ||||||||||||||||||||||||||||||||
| off | - | 相对位置来设置输出位置指示器.
Original: relative position to set the output position indicator to. The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | ||||||||||||||||||||||||||||||||
| dir | - | 定义应用的相对偏移量的基础地位。它可以是以下常量之一:
Original: defines base position to apply the relative offset to. It can be one of the following constants:
The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | ||||||||||||||||||||||||||||||||
[编辑] 返回值
*this
[编辑] 例外
1)在失败的情况下,可能会引发std::ios_base::failure,如果exceptions() & failbit != 0.
2) Original:
May throw std::ios_base::failure in case of failure, if exceptions() & failbit != 0.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
不会抛出,除非rdbuf()->pubseekoff()抛出
Original:
Does not throw unless rdbuf()->pubseekoff() throws
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
#include <sstream> #include <iostream> int main() { std::ostringstream os("hello, world"); os.seekp(7); os << 'W'; os.seekp(0, std::ios_base::end); os << '!'; os.seekp(0); os << 'H'; std::cout << os.str() << '\n'; }
Output:
Hello, World!
[编辑] 另请参阅
| 返回的输出位置指示器 Original: returns the output position indicator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 返回输入位置指示器 Original: returns the input position indicator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数of std::basic_istream)
| |
| sets the input position indicator (公共成员函数of std::basic_istream)
| |