Namespaces
Variants

std::ostrstream:: pcount

From cppreference.net

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 の公開メンバ関数 )