std::ostream_iterator<T,CharT,Traits>:: ostream_iterator
From cppreference.net
<
cpp
|
iterator
|
ostream iterator
C++
Iterator library
| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::ostream_iterator
| Member functions | ||||
|
ostream_iterator::ostream_iterator
|
||||
|
ostream_iterator
(
ostream_type
&
stream,
const
CharT
*
delim
)
;
|
(1) | |
|
ostream_iterator
(
ostream_type
&
stream
)
;
|
(2) | |
Construit l'itérateur avec stream comme flux associé, en stockant l'adresse de stream .
1)
Utilise
delim
comme délimiteur.
2)
Utilise un pointeur nul comme délimiteur.
Paramètres
| stream | - | le flux de sortie auquel cet itérateur accède |
| delim | - | la chaîne de caractères terminée par un caractère nul à insérer dans le flux après chaque sortie |
Exemple
Exécuter ce code
#include <algorithm> #include <iostream> #include <iterator> #include <numeric> int main() { std::ostream_iterator<char> oo{std::cout}; std::ostream_iterator<int> i1{std::cout, ", "}; std::fill_n(i1, 5, -1); *oo++ = '\n'; std::ostream_iterator<double> i2{std::cout, "; "}; *i2++ = 3.14; *i2++ = 2.71; *oo++ = '\n'; std::common_iterator<std::counted_iterator<std::ostream_iterator<float>>, std::default_sentinel_t> first{std::counted_iterator{std::ostream_iterator<float>{std::cout," ~ "}, 5}}, last{std::default_sentinel}; std::iota(first, last, 2.2); *oo++ = '\n'; }
Sortie :
-1, -1, -1, -1, -1, 3.14; 2.71; 2.2 ~ 3.2 ~ 4.2 ~ 5.2 ~ 6.2 ~
Rapports de défauts
Les rapports de défauts modifiant le comportement suivants ont été appliqués rétroactivement aux normes C++ précédemment publiées.
| DR | Appliqué à | Comportement publié | Comportement corrigé |
|---|---|---|---|
| LWG 1280 | C++98 | stream était stocké directement | stocke son adresse à la place |
| P2325R3 | C++20 |
le constructeur par défaut était fourni car C++20
les itérateurs doivent être
default_initializable
|
supprimé ainsi que
l'exigence |