std::ostringstream — building text with a stream
std::ostringstream, declared in <sstream>, formats values into text stored in memory. It uses operator << like an output stream, while str() retrieves the result as a std::string.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
std::ostringstream, declared in <sstream>, formats values into text stored in memory. It uses operator << like an output stream, while str() retrieves the result as a std::string.
std::out_of_range, declared in <stdexcept>, reports an argument value outside its expected range. It carries a message available through what() and derives from std::logic_error.
std::overflow_error, declared in <stdexcept>, reports arithmetic overflow. It does not detect overflow automatically: code must check bounds before a risky operation and explicitly throw the exception.
std::packaged_task wraps a callable and stores its result or exception in shared state. std::packaged_task::get_future provides a std::future for retrieving that result; the task itself does not start a new thread.
std::pair<T1, T2> groups two values, potentially of different types, in one object. Its public first and second data members provide direct access to the first and second elements.
std::partial_ordering from <compare> represents a comparison result that can be less, equivalent, greater, or unordered. The unordered state means the values are incomparable, not equivalent.
std::partial_sort selects the smallest k elements and places them in a sorted prefix of the range. It modifies the input, while the order of the remaining elements is unspecified.
std::partial_sum from <numeric> writes successive prefix sums of a range. It also accepts a custom binary operation; its accumulator uses the input value type, independently of the output type.
std::partition rearranges a range so that elements satisfying a predicate precede the others. It returns the boundary iterator between the groups, but does not guarantee that order within either group is preserved.
std::plus from <functional> exposes operator + as a callable object. std::plus<T> fixes the type T, whereas std::plus<> deduces the argument types and the expression's result type.
std::pmr::memory_resource is an abstract interface for allocating and deallocating storage with a specified alignment. It enables runtime selection of an allocation strategy, while std::pmr::polymorphic_allocator connects that interface to code expecting an allocator.
std::pmr::monotonic_buffer_resource supplies storage for successive allocations while ignoring individual deallocations. release() returns upstream blocks and resets the resource for reuse.
std::pmr::polymorphic_allocator<T>, declared in <memory_resource>, routes memory requests to a std::pmr::memory_resource object. It lets allocation strategies vary at runtime without changing the allocator type or the container type that uses it.
std::pmr::string is a std::basic_string specialization using std::pmr::polymorphic_allocator<char>. It lets you select a memory resource at runtime without changing the string's type.
std::pmr::synchronized_pool_resource manages pools of memory blocks and supports concurrent access from multiple threads. It can supply storage to PMR containers, but resource synchronization does not make concurrent modifications of a container safe.
std::pmr::unsynchronized_pool_resource manages pools of memory blocks for polymorphic allocators. It allows deallocated blocks to be reused, but requires careful resource lifetimes and prevention of simultaneous access from multiple threads.
std::pop_heap moves the root of a nonempty heap to the end of the range and restores the heap in the remaining prefix. It does not erase a container element. For std::vector, pop_back() removes the extracted element only if the heap range ends at the end of the vector.
std::prev from <iterator> returns a shifted copy of a bidirectional iterator without changing the argument. It moves backward by one step by default; negative n means moving forward. The caller must ensure that the movement stays within valid bounds and that evaluating -n does not overflow.
std::prev_permutation rearranges a range into its previous lexicographical permutation. It returns bool; when no previous permutation exists, it rearranges the range into the last permutation and returns false.
std::print from <print> writes formatted data to stdout or a specified FILE* stream. It uses replacement fields such as {} and does not automatically append a newline.
std::println from <print> formats arguments, writes the result, and appends a newline. It uses stdout by default; an overload accepting FILE* lets you select another output stream.
std::priority_queue exposes the highest-priority element rather than the earliest inserted one. By default, the largest value is on top; std::greater<T> reverses the ordering.
std::promise<T> stores a single result in shared state read through std::future<T>. The result can be a value or an exception; the promise object itself does not start a computation or thread.
std::push_heap restores the heap property after one element has been appended to a range. It does not grow the container: the new element must already be at last - 1, and the preceding part of the range must already be a valid heap.