命名空间
变体
操作

std::strstream::pcount

来自 cppreference.cn
< cpp‎ | io‎ | strstream
int pcount() const;
(C++98 中已弃用)
(C++26 中已移除)

返回与 std::strstreambuf 关联的放置区域中输出的字符数。 有效调用 rdbuf()->pcount()

内容

[编辑] 参数

(无)

[编辑] 返回值

放置区域中的字符数,如果未输出任何内容,则为零。

[编辑] 示例

#include <iostream>
#include <strstream>
 
int main()
{
    std::strstream dyn; // dynamically-allocated output buffer
    dyn << "Test: " << 1.23 << std::ends;
    std::cout << "The size of the output is " << dyn.pcount()
              << " and it holds \"" << dyn.str() << "\"\n";
    dyn.freeze(false);
 
    char buf[10];
    std::strstream user(buf, 10); // user-provided output buffer
    user << 1.23; // note: no std::ends
    std::cout.write(buf, user.pcount());
    std::cout << '\n';
}

输出

The size of the output is 11 and it holds "Test: 1.23"
1.23

[编辑] 参见

返回输出序列中下一个指针减去起始指针的值:写入的字符数
(std::strstreambuf 的公共成员函数) [编辑]