std::strstreambuf::pcount
来自 cppreference.cn
< cpp | io | strstreambuf
int pcount() const; |
(C++98 弃用) (C++26 移除) |
|
返回写入到输出序列的字符数。
如果放置区域的下一个指针 (std::streambuf::pptr()) 是空指针,则返回零。
否则,返回放置区域的下一个指针减去放置区域的起始指针,即 pptr() - pbase()。
目录 |
[edit] 参数
(无)
[edit] 返回值
写入到放置区域的字符数。
[edit] 示例
运行此代码
#include <iostream> #include <strstream> 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'; }
输出
The size of the output is 11 and it holds "Test: 1.23" 1.23 Input-only pcount() = 0
[edit] 参见
获取写入的字符数 (std::strstream 的公共成员函数) | |
获取写入的字符数 (std::ostrstream 的公共成员函数) |