首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_ostream::seekp

basic_ostream& seekp( pos_type pos );

(1)

?

basic_ostream& seekp( off_type off, std::ios_base::seekdir dir);

(2)

?

设置当前关联的输出位置指示符。streambuf对象。

Behaves as UnformattedOutputFunction (except without actually performing output). After constructing and checking the sentry object,

(since C++11)

1%29将输出位置指示符设置为相对于文件%29值开头的绝对%28。pos打电话rdbuf()->pubseekpos(pos,std::ios_base::out).如果呼叫返回(pos_type)-1,执行setstate(failbit)...

2%29将输出位置指示器设置为偏移。off相对于dir打电话rdbuf()->pubseekoff(off, dir,std::ios_base::out)...

Does not report errors.

(until C++14)

If the call returns (pos_type)-1, executes setstate(failbit).

(since C++14)

参数

pos

-

absolute position to set the output position indicator to.

off

-

relative position to set the output position indicator to.

dir

-

defines base position to apply the relative offset to. It can be one of the following constants: Constant Explanation beg the beginning of a stream end the ending of a stream cur the current position of stream position indicator

Constant

Explanation

beg

the beginning of a stream

end

the ending of a stream

cur

the current position of stream position indicator

Constant

Explanation

beg

the beginning of a stream

end

the ending of a stream

cur

the current position of stream position indicator

返回值

*this...

例外

1%5月29日投掷std::ios_base::failure如果失败,如果exceptions() & failbit != 0...

2%29

Does not throw unless rdbuf()->pubseekoff() throws

(until C++14)

May throw std::ios_base::failure in case of failure, if exceptions() & failbit != 0.

(since C++14)

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
Hello, World!

二次

另见

tellp

returns the output position indicator (public member function)

tellg

returns the input position indicator (public member function of std::basic_istream)

seekg

sets the input position indicator (public member function of std::basic_istream)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com