std::ostrstream::pcount
来自 cppreference.cn
< cpp | io | ostrstream
int pcount() const; |
(C++98 已弃用) (C++26 已移除) |
|
返回关联的 std::strstreambuf 的放置区域中已输出的字符数。 有效地调用 rdbuf()->pcount()。
内容 |
[编辑] 参数
(无)
[编辑] 返回值
放置区域中的字符数,如果未输出任何内容,则为零。
[编辑] 示例
运行此代码
#include <iostream> #include <strstream> int main() { std::ostrstream 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::ostrstream 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 的公有成员函数) |