std::ostrstream:: pcount
From cppreference.net
<
cpp
|
io
|
ostrstream
|
int
pcount
(
)
const
;
|
(C++98 中已弃用)
(C++26 中移除) |
|
返回在关联的 std:: strstreambuf 输出区域中输出的字符数量。实际上调用 rdbuf ( ) - > pcount ( ) 。
目录 |
参数
(无)
返回值
输出区域中的字符数量,如果未输出任何内容则为零。
示例
运行此代码
#include <iostream> #include <strstream> int main() { std::ostrstream dyn; // 动态分配的输出缓冲区 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 << 1.23; // 注意:未使用 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
的公开成员函数)
|