std::basic_ostringstream<CharT,Traits,Allocator>:: basic_ostringstream
| (1) | ||
|
explicit
basic_ostringstream
(
std::
ios_base
::
openmode
mode
=
std:: ios_base :: out ) ; |
(jusqu'à C++11) | |
|
explicit
basic_ostringstream
(
std::
ios_base
::
openmode
mode
)
;
|
(depuis C++11) | |
|
basic_ostringstream
(
)
: basic_ostringstream ( std:: ios_base :: out ) { } |
(2) | (depuis C++11) |
|
explicit
basic_ostringstream
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
str,
|
(3) | |
|
explicit
basic_ostringstream
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
str,
|
(4) | (depuis C++20) |
|
basic_ostringstream
(
std::
ios_base
::
openmode
mode,
const
Allocator
&
a
)
;
|
(5) | (depuis C++20) |
|
template
<
class
SAlloc
>
basic_ostringstream
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
str,
|
(6) | (depuis C++20) |
|
template
<
class
SAlloc
>
basic_ostringstream
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
str,
|
(7) | (depuis C++20) |
|
template
<
class
SAlloc
>
explicit
basic_ostringstream
|
(8) | (depuis C++20) |
|
template
<
class
StringViewLike
>
explicit
basic_ostringstream
|
(9) | (depuis C++26) |
|
template
<
class
StringViewLike
>
basic_ostringstream
(
const
StringViewLike
&
t,
|
(10) | (depuis C++26) |
|
template
<
class
StringViewLike
>
basic_ostringstream ( const StringViewLike & t, const Allocator & a ) ; |
(11) | (depuis C++26) |
|
basic_ostringstream
(
basic_ostringstream
&&
other
)
;
|
(12) | (depuis C++11) |
Construit un nouveau flux de chaîne.
Étant donné
-
base_typecomme std:: basic_ostream < CharT, Traits > , et -
buf_typecomme std:: basic_stringbuf < CharT, Traits, Allocator > ,
la base
std::basic_ostream
et le
membre de données exposition-only
sb
sont initialisés comme suit.
|
Surcharge
de fonction |
std::basic_ostream base |
sb
|
|---|---|---|
| (1) | base_type ( std:: addressof ( sb ) ) [1] | buf_type ( mode | std:: ios_base :: out ) |
| (2) | buf_type ( std:: ios_base :: out ) | |
| (3) | buf_type ( str, mode | std:: ios_base :: out ) | |
| (4) | buf_type ( std :: move ( str ) , mode | std:: ios_base :: out ) | |
| (5) | buf_type ( mode | std:: ios_base :: out , a ) | |
| (6) | buf_type ( str, mode | std:: ios_base :: out , a ) | |
| (7) | buf_type ( str, std:: ios_base :: out , a ) | |
| (8) | buf_type ( str, mode | std:: ios_base :: out ) | |
| (9) | std:: addressof ( sb ) | { t, mode | std:: ios_base :: out , Allocator ( ) } |
| (10) | { t, mode | std:: ios_base :: out , a } | |
| (11) | { t, std:: ios_base :: out , a } | |
| (12) | construit par déplacement depuis la other 's std::basic_ostream base | construit par déplacement depuis other. sb |
- ↑ La std::basic_iostream de base était initialisée avec base_type ( & sb ) (pour les surcharges (1,3) ) jusqu'à C++11.
Table des matières |
Paramètres
| str | - | chaîne à utiliser comme contenu initial du flux de chaîne | ||||||||||||||||
| t | - | un objet (convertible en std::basic_string_view ) à utiliser comme contenu initial du flux de chaîne | ||||||||||||||||
| a | - | allocateur utilisé pour allouer le contenu du flux de chaîne | ||||||||||||||||
| mode | - |
spécifie le mode d'ouverture du flux. C'est un
BitmaskType
, les constantes suivantes sont définies :
|
||||||||||||||||
| other | - | un autre flux de chaîne à utiliser comme source |
Notes
La construction d'objets
basic_ostringstream
uniques dans une boucle serrée, comme lorsqu'ils sont utilisés pour la conversion de chaînes, peut être considérablement plus coûteuse que l'appel à
str()
pour réutiliser le même objet.
| Macro de test de fonctionnalité | Valeur | Std | Fonctionnalité |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | Interface entre std::stringstream et std::string_view , ( 9-11 ) |
Exemple
#include <iostream> #include <sstream> int main() { // constructeur par défaut (flux d'entrée/sortie) std::stringstream buf1; buf1 << 7; int n = 0; buf1 >> n; std::cout << "buf1 = " << buf1.str() << " n = " << n << '\n'; // flux d'entrée std::istringstream inbuf("-10"); inbuf >> n; std::cout << "n = " << n << '\n'; // flux de sortie en mode append (C++11) std::ostringstream buf2("test", std::ios_base::ate); buf2 << '1'; std::cout << buf2.str() << '\n'; }
Sortie :
buf1 = 7 n = 7 n = -10 test1
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é |
|---|---|---|---|
| P0935R0 | C++11 | le constructeur par défaut était explicite | rendu implicite |
Voir aussi
|
obtient ou définit le contenu de l'objet de chaîne sous-jacent
(fonction membre publique) |
|
construit un objet
basic_stringbuf
(fonction membre publique de
std::basic_stringbuf<CharT,Traits,Allocator>
)
|