名前空間
変種
操作

std::strstreambuf::pcount

提供: cppreference.com
< cpp‎ | io‎ | strstreambuf
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
int pcount() const;

出力シーケンスに書き込まれた文字数を返します。

put 領域の次ポインタ (std::streambuf::pptr()) がヌルポインタの場合は、ゼロを返します。

そうでなければ、 put 領域の次ポインタから put 領域の先頭ポインタを引いた値、すなわち pptr() - pbase() を返します。

目次

[編集] 引数

(なし)

[編集] 戻り値

put 領域に書き込まれた文字数。

[編集]

#include <strstream>
#include <iostream>
 
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のパブリックメンバ関数) [edit]
書き込まれた文字数を取得します
(std::ostrstreamのパブリックメンバ関数) [edit]