std::strstreambuf::pcount

来自cppreference.com
< cpp‎ | io‎ | strstreambuf
int pcount()const;
(C++98 弃用)
(C++26 移除)

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

若放置区的下一位置指针(std::streambuf::pptr())为空指针,则返回零。

否则,返回放置区中的下一位置指针减放置区中的起始指针,即 pptr()- pbase()

目录

[编辑]参数

(无)

[编辑]返回值

写入放置区的字符数。

[编辑]示例

#include <iostream>#include <strstream>   int main(){std::strstream dyn;// 动态分配的输出缓冲区 dyn <<"Test: "<<1.23<<std::ends;std::strstreambuf* buf = dyn.rdbuf();std::cout<<"输出的大小为 "<< buf->pcount()// 或用 buf.pcount()<<" 并持有 \""<< dyn.str()<<"\"\n"; dyn.freeze(false);// 在动态流上调用 .str() 后   char arr[10];std::ostrstream user(arr, 10);// 用户提供的输出缓冲区 buf = user.rdbuf(); user <<1.23;// 注意:无 std::endsstd::cout.write(arr, buf->pcount());// 或就是 user.pcount()std::cout<<'\n';   std::istrstream lit("1 2 3");// 只读固定大小缓冲区 buf = lit.rdbuf();// istrstream 无成员 pcount() ,故 lit.pcount() 将不工作std::cout<<"仅输入的 pcount() = "<< buf->pcount()<<'\n';}

输出:

输出的大小为 11 并持有 "Test: 1.23" 1.23 仅输入的 pcount() = 0

[编辑]参阅

获得写入的字符数
(std::strstream 的公开成员函数)[编辑]
获得写入的字符数
(std::ostrstream 的公开成员函数)[编辑]
close