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

std::strstreambuf::pcount

int pcount() const;

?

?

返回写入输出序列的字符数。

如果PUT区域%28的下一个指针std::streambuf::pptr()%29是空指针,返回零。

否则,返回PUT区域中的下一个指针减去PUT区域中的起始指针,即pptr() - pbase()...

参数

%280%29

返回值

写入PUT区域的字符数。

二次

代码语言:javascript
复制
#include <strstream>
#include <iostream>
 
int main()
{
    std::strstream dyn; // dynamically-allocated output buffer
    dyn << "Test: " << 1.23 << std::ends;
    std::strstreambuf* buf = dyn.rdbuf();
    std::cout << "The size of the output is "
              << buf->pcount() // or just buf.pcount()
              << " and it holds \"" << dyn.str() << "\"\n";
    dyn.freeze(false); // after calling .str() on a dynamic strstream
 
    char arr[10];
    std::ostrstream user(arr, 10); // user-provided output buffer
    buf = user.rdbuf();
    user << 1.23; // note: no std::ends
    std::cout.write(arr, buf->pcount()); // or just user.pcount()
    std::cout << '\n';
 
    std::istrstream lit("1 2 3"); // read-only fixed-size buffer
    buf = lit.rdbuf();
    // istrstream has no member pcount(), so lit.pcount() won't work
    std::cout << "Input-only pcount() = " << buf->pcount() << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
The size of the output is 11 and it holds "Test: 1.23"
1.23
Input-only pcount() = 0

二次

另见

pcount

obtains the number of characters written (public member function of std::strstream)

pcount

obtains the number of characters written (public member function of std::ostrstream)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com