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; // 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
[編輯] 參閱
獲取已寫入的字元數 ( std::strstream 的公共成員函式) | |
獲取已寫入的字元數 ( std::ostrstream 的公共成員函式) |