Spec-Zone.ru › C++

std::strstreambuf::pcount

int pcount() const;

Возвращает количество символов, записанных в выходной последовательности.

Если указатель на следующий символ в области записи (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

См. также

pcount
получает количество записанных символов
(общедоступный член-функция std::strstream)
pcount
получает количество записанных символов
(общедоступный член-функция std::ostrstream)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/io/strstreambuf/pcount

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API