std::basic_stringbuf<CharT,Traits,Allocator>:: basic_stringbuf
| (1) | ||
|
explicit
basic_stringbuf
(
std::
ios_base
::
openmode
which
=
std:: ios_base :: in | std:: ios_base :: out ) ; |
(jusqu'en C++11) | |
|
explicit
basic_stringbuf
(
std::
ios_base
::
openmode
which
)
;
|
(depuis C++11) | |
|
basic_stringbuf
(
)
: basic_stringbuf ( std:: ios_base :: in | std:: ios_base :: out ) { } |
(2) | (depuis C++11) |
|
explicit
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
s,
|
(3) | |
|
explicit
basic_stringbuf
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
s,
std::
ios_base
::
openmode
mode
=
|
(4) | (depuis C++20) |
|
basic_stringbuf
(
std::
ios_base
::
openmode
which,
const
Allocator
&
a
)
;
|
(5) | (depuis C++20) |
|
explicit
basic_stringbuf
(
const
Allocator
&
a
)
: basic_stringbuf ( std:: ios_base :: in | std:: ios_base :: out , a ) { } |
(6) | (depuis C++20) |
|
template
<
class
SAlloc
>
explicit
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
s,
|
(7) | (depuis C++20) |
|
template
<
class
SAlloc
>
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
s,
|
(8) | (depuis C++20) |
|
template
<
class
SAlloc
>
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
s,
|
(9) | (depuis C++20) |
|
template
<
class
StringViewLike
>
explicit
basic_stringbuf
(
const
StringViewLike
&
t,
|
(10) | (depuis C++26) |
|
template
<
class
StringViewLike
>
basic_stringbuf
(
const
StringViewLike
&
t,
|
(11) | (depuis C++26) |
|
template
<
class
StringViewLike
>
basic_stringbuf ( const StringViewLike & t, const Allocator & a ) ; |
(12) | (depuis C++26) |
|
basic_stringbuf
(
basic_stringbuf
&&
rhs
)
;
|
(13) | (depuis C++11) |
|
basic_stringbuf
(
basic_stringbuf
&&
rhs,
const
Allocator
&
a
)
;
|
(14) | (depuis C++20) |
|
basic_stringbuf
(
const
basic_stringbuf
&
rhs
)
=
delete
;
|
(15) | (depuis C++11) |
La base
std::basic_streambuf
et les
membres de données exposition-only
buf
et
mode
sont initialisés comme suit.
Après l'initialisation de ces sous-objets, les surcharges
(3-12)
initialisent les séquences d'entrée et de sortie comme si elles appelaient
init_buf_ptrs
()
.
| Surcharge | std::basic_streambuf base |
buf
|
mode
|
|---|---|---|---|
| (1) | initialisé par défaut |
défini par l'implémentation
(voir ci-dessous) |
which |
| (2) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (3) | s | which | |
| (4) | std :: move ( s ) | ||
| (5) | a | ||
| (6) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (7) | s | which | |
| (8) | { s, a } | ||
| (9) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (10) | { sv, Allocator ( ) } | which | |
| (11) | { sv, a } | ||
| (12) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (13) |
rhs
(copie construite) |
std :: move ( rhs ) . str ( ) | rhs. mode |
| (14) | { std :: move ( rhs ) . str ( ) , a } |
std:: basic_string_view < CharT, Traits >> est true .
- Soit rhs_p l'état de rhs juste avant cette construction, les expressions suivantes évalueront à true :
-
- str ( ) == rhs_p. str ( )
- getloc ( ) == rhs_p. getloc ( )
- gptr ( ) - eback ( ) == rhs_p. gptr ( ) - rhs_p. eback ( )
- egptr ( ) - eback ( ) == rhs_p. egptr ( ) - rhs_p. eback ( )
- pptr ( ) - pbase ( ) == rhs_p. pptr ( ) - rhs_p. pbase ( )
- epptr ( ) - pbase ( ) == rhs_p. epptr ( ) - rhs_p. pbase ( )
- Soit rhs_a l'état de rhs juste après cette construction, les expressions suivantes évalueront à true :
-
- ! eback ( ) || eback ( ) ! = rhs_a. eback ( )
- ! gptr ( ) || gptr ( ) ! = rhs_a. gptr ( )
- ! egptr ( ) || egptr ( ) ! = rhs_a. egptr ( )
- ! pbase ( ) || pbase ( ) ! = rhs_a. pbase ( )
- ! pptr ( ) || pptr ( ) ! = rhs_a. pptr ( )
- ! epptr ( ) || epptr ( ) ! = rhs_a. epptr ( )
Table des matières |
Paramètres
| s | - | une std::basic_string utilisée pour initialiser le tampon | ||||||||||||||||
| t | - | un objet (convertible en std::basic_string_view ) utilisé pour initialiser le tampon | ||||||||||||||||
| a | - | un autre allocateur utilisé pour construire la std::basic_string interne | ||||||||||||||||
| rhs | - |
un autre
basic_stringbuf
|
||||||||||||||||
| which | - |
spécifie le mode d'ouverture du flux. C'est un type masque de bits, les constantes suivantes sont définies :
|
Notes
Généralement appelé par le constructeur de std::basic_stringstream .
Le niveau de support pour les modes d'ouverture autres que std::ios_base::in et std::ios_base::out varie selon les implémentations. C++11 spécifie explicitement le support pour std::ios_base::ate dans str() et dans ce constructeur, mais std::ios_base::app , std::ios_base::trunc , et std::ios_base::binary ont des effets différents selon les implémentations.
| Macro de test de fonctionnalité | Valeur | Norme | Fonctionnalité |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | Interface des flux de chaînes avec std::string_view |
Exemple
Démontre l'appel direct du constructeur de
std::basic_stringbuf
:
#include <iostream> #include <sstream> int main() { // constructeur par défaut (mode = in | out) std::stringbuf buf1; buf1.sputc('1'); std::cout << &buf1 << '\n'; // constructeur avec chaîne en mode at-end (C++11) std::stringbuf buf2("test", std::ios_base::in | std::ios_base::out | std::ios_base::ate); buf2.sputc('1'); std::cout << &buf2 << '\n'; // test du mode append (les résultats varient selon les compilateurs) std::stringbuf buf3("test", std::ios_base::in | std::ios_base::out | std::ios_base::app); buf3.sputc('1'); buf3.pubseekpos(1); buf3.sputc('2'); std::cout << &buf3 << '\n'; }
Sortie :
1 test1 est12 (Sun Studio) 2st1 (GCC)
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 | Applicable à | Comportement publié | Comportement corrigé |
|---|---|---|---|
| LWG 432 | C++98 |
1. la surcharge
(1)
n'allouait aucun objet tableau
2. la surcharge (3) ne spécifiait pas comment les séquences d'entrée et de sortie sont initialisées |
1. limitation supprimée
2. spécifié |
| LWG 562 | C++98 |
la surcharge
(3)
positionnait
epptr()
à pointer après le dernier caractère
sous-jacent si bool ( which & std:: ios_base :: out ) == true |
epptr()
peut être positionné
au-delà de cette position |
| P0935R0 | C++11 | le constructeur par défaut était explicite | rendu implicite |
Voir aussi
|
construit le flux de chaîne
(fonction membre publique de
std::basic_stringstream<CharT,Traits,Allocator>
)
|