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

std::basic_ostream::tellp

pos_type tellp();

?

?

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

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

(since C++11)

如果fail()==true、回报pos_type(-1).否则,返回rdbuf()->pubseekoff(0,std::ios_base::cur,std::ios_base::out)...

参数

%280%29

返回值

当前成功输出位置指示符,pos_type(-1)如果发生故障。

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
int main()
{
    std::ostringstream s;
    std::cout << s.tellp() << '\n';
    s << 'h';
    std::cout << s.tellp() << '\n';
    s << "ello, world ";
    std::cout << s.tellp() << '\n';
    s << 3.14 << '\n';
    std::cout << s.tellp() << '\n' << s.str();
}

二次

产出:

二次

代码语言:javascript
复制
0
1
13
18
hello, world 3.14

二次

另见

seekp

sets 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