---
name: "std::ostream_iterator"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::ostream_iterator"
---

# std::ostream\_iterator(3)

Provides output iterator semantics for streams.

## NAME

std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \> - Provides output iterator semantics for streams.

## SYNOPSIS

\#include \<iterator\>

Inherits **std::iterator\< output\_iterator\_tag, void, void, void, void \>**.

### Public Types

typedef **output\_iterator\_tag** **iterator\_category**\
 One of the **tag types**.  typedef void **pointer**\
 This type represents a pointer-to-value\_type.  typedef void **reference**\
 This type represents a reference-to-value\_type.  typedef void **value\_type**\
 The type *pointed*to"*by*the*iterator.*

using **difference\_type**\
 Public typedef.  typedef \_CharT **char\_type**\
 Public typedef.  typedef \_Traits **traits\_type**\
 Public typedef.  typedef **basic\_ostream**\< \_CharT, \_Traits \> **ostream\_type**\
 Public typedef.

### Public Member Functions

**ostream\_iterator** (const ostream\_iterator &\_\_obj) noexcept\
 Copy constructor.  **ostream\_iterator** (**ostream\_type** &\_\_s) noexcept\
 Construct from an ostream.  **ostream\_iterator** (**ostream\_type** &\_\_s, const \_CharT \*\_\_c) noexcept\
 **ostream\_iterator** & **operator\*** () noexcept\
 **ostream\_iterator** & **operator++** () noexcept\
 **ostream\_iterator** & **operator++** (int) noexcept\
 **ostream\_iterator** & **operator=** (const \_Tp &\_\_value)\
 Writes *value* to underlying ostream using operator\<\<. If constructed with delimiter string, writes delimiter to ostream.  **ostream\_iterator** & **operator=** (const **ostream\_iterator** &)=default\

## Detailed Description

### template\<typename \_Tp, typename \_CharT = char, typename \_Traits = char\_traits\<\_CharT\>\>

class std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \>"Provides output iterator semantics for streams.

This class provides an iterator to write to an ostream. The type Tp is the only type written by this iterator and there must be an operator\<\<(Tp) defined.

**Template Parameters**

*\_Tp* The type to write to the ostream. \
 *\_CharT* The ostream char\_type. \
 *\_Traits* The ostream char\_traits.

## Member Typedef Documentation

### template\<typename \_Tp, typename \_CharT = char, typename \_Traits = char\_traits\<\_CharT\>\> typedef \_CharT std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \>::char\_type

Public typedef.

### template\<typename \_Tp, typename \_CharT = char, typename \_Traits = char\_traits\<\_CharT\>\> using std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \>::difference\_type

Public typedef.

### typedef output\_iterator\_tag std::iterator\< output\_iterator\_tag, void, void, void, void \>::iterator\_category \[inherited\]

One of the **tag types**.

### template\<typename \_Tp, typename \_CharT = char, typename \_Traits = char\_traits\<\_CharT\>\> typedef basic\_ostream\<\_CharT, \_Traits\> std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \>::ostream\_type

Public typedef.

### typedef void std::iterator\< output\_iterator\_tag, void, void, void, void \>::pointer \[inherited\]

This type represents a pointer-to-value\_type.

### typedef void std::iterator\< output\_iterator\_tag, void, void, void, void \>::reference \[inherited\]

This type represents a reference-to-value\_type.

### template\<typename \_Tp, typename \_CharT = char, typename \_Traits = char\_traits\<\_CharT\>\> typedef \_Traits std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \>::traits\_type

Public typedef.

### typedef void std::iterator\< output\_iterator\_tag, void, void, void, void \>::value\_type \[inherited\]

The type "pointed to" by the iterator.

## Constructor & Destructor Documentation

### template\<typename \_Tp, typename \_CharT = char, typename \_Traits = char\_traits\<\_CharT\>\> std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \>::ostream\_iterator (ostream\_type & \_\_s) \[inline\], \[noexcept\]

Construct from an ostream.

References **std::\_\_addressof()**.

Referenced by **ostream\_iterator()**.

### template\<typename \_Tp, typename \_CharT = char, typename \_Traits = char\_traits\<\_CharT\>\> std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \>::ostream\_iterator (ostream\_type & \_\_s, const \_CharT \* \_\_c) \[inline\], \[noexcept\]

Construct from an ostream.

The delimiter string *c* is written to the stream after every Tp written to the stream. The delimiter is not copied, and thus must not be destroyed while this iterator is in use.

**Parameters**

*\_\_s* Underlying ostream to write to. \
 *\_\_c* CharT delimiter string to insert.

References **std::\_\_addressof()**.

### template\<typename \_Tp, typename \_CharT = char, typename \_Traits = char\_traits\<\_CharT\>\> std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \>::ostream\_iterator (const ostream\_iterator\< \_Tp, \_CharT, \_Traits \> & \_\_obj) \[inline\], \[noexcept\]

Copy constructor.

References **ostream\_iterator()**.

## Member Function Documentation

### template\<typename \_Tp, typename \_CharT = char, typename \_Traits = char\_traits\<\_CharT\>\> ostream\_iterator & std::ostream\_iterator\< \_Tp, \_CharT, \_Traits \>::operator= (const \_Tp & \_\_value) \[inline\]

Writes *value* to underlying ostream using operator\<\<. If constructed with delimiter string, writes delimiter to ostream.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
