std::strstream::freeze
void freeze(bool flag = true); |
Если поток использует динамически выделенный массив для вывода, отключает (flag == true) или включает (flag == false) автоматическое выделение/освобождение буфера. Эффективно вызывает rdbuf()->freeze(flag).
Примечания
После вызова str(), динамические потоки автоматически замораживаются. Перед выходом из области видимости, в которой был создан этот strstream объект, требуется вызвать freeze(false). В противном случае деструктор будет утечка памяти. Кроме того, дополнительный вывод в замороженный поток может быть усечён, когда он достигнет конца выделенного буфера.
Параметры
| flag | - | желаемый статус |
Возвращаемое значение
(ничего)
Пример
#include <iostream>
#include <strstream>
int main()
{
std::strstream dyn; // dynamically-allocated output buffer
dyn << "Test: " << 1.23; // note: no std::ends to demonstrate appending
std::cout << "The output stream contains \"";
std::cout.write(dyn.str(), dyn.pcount()) << "\"\n";
// the stream is now frozen due to str()
dyn << " More text"; // output to a frozen stream may be truncated
std::cout << "The output stream contains \"";
std::cout.write(dyn.str(), dyn.pcount()) << "\"\n";
dyn.freeze(false); // freeze(false) must be called or the destructor will leak
std::strstream dyn2; // dynamically-allocated output buffer
dyn2 << "Test: " << 1.23; // note: no std::ends
std::cout << "The output stream contains \"";
std::cout.write(dyn2.str(), dyn2.pcount()) << "\"\n";
dyn2.freeze(false); // unfreeze the stream after str()
dyn2 << " More text" << std::ends; // output will not be truncated (buffer grows)
std::cout << "The output stream contains \"" << dyn2.str() << "\"\n";
dyn2.freeze(false); // freeze(false) must be called or the destructor will leak
}Возможный вывод:
The output stream contains "Test: 1.23" The output stream contains "Test: 1.23 More " The output stream contains "Test: 1.23" The output stream contains "Test: 1.23 More text"
См. также
| устанавливает/сбрасывает замороженное состояние буфера (общедоступный член-функция std::strstreambuf) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/io/strstream/freeze