std::basic_ostringstream<CharT,Traits,Allocator>:: str
| (1) | ||
|
std::
basic_string
<
CharT, Traits, Allocator
>
str
(
)
const
;
|
(jusqu'à C++20) | |
|
std::
basic_string
<
CharT, Traits, Allocator
>
str
(
)
const
&
;
|
(depuis C++20) | |
|
template
<
class
SAlloc
>
std:: basic_string < CharT, Traits, SAlloc > str ( const SAlloc & a ) const ; |
(2) | (depuis C++20) |
|
std::
basic_string
<
CharT, Traits, Allocator
>
str
(
)
&&
;
|
(3) | (depuis C++20) |
|
void
str
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
s
)
;
|
(4) | |
|
template
<
class
SAlloc
>
void str ( const std:: basic_string < CharT, Traits, SAlloc > & s ) ; |
(5) | (depuis C++20) |
|
void
str
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
s
)
;
|
(6) | (depuis C++20) |
|
template
<
class
StringViewLike
>
void str ( const StringViewLike & t ) ; |
(7) | (depuis C++26) |
Gère le contenu de l'objet chaîne sous-jacent.
Table des matières |
Paramètres
| s | - | nouveau contenu de la chaîne sous-jacente |
| t | - | un objet (convertible en std::basic_string_view ) à utiliser comme nouveau contenu de la chaîne sous-jacente |
| a | - | allocateur utilisé pour construire la chaîne retournée |
Valeur de retour
Notes
La copie de la chaîne sous-jacente retournée par
str
est un objet temporaire qui sera détruit à la fin de l'expression, donc appeler directement
c_str()
sur le résultat de
str
(
)
(par exemple dans
auto
*
ptr
=
out.
str
(
)
.
c_str
(
)
;
) résulte en un pointeur suspendu.
| Macro de test de fonctionnalité | Valeur | Std | Fonctionnalité |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | Interfacement des std::stringstream avec std::string_view , ( 7 ) |
Exemple
#include <iostream> #include <sstream> int main() { int n; std::istringstream in; // pourrait aussi utiliser in("1 2") in.str("1 2"); in >> n; std::cout << "After reading the first int from \"1 2\", the int is " << n << ", str() = \"" << in.str() << "\"\n"; std::ostringstream out("1 2"); out << 3; std::cout << "After writing the int '3' to output stream \"1 2\"" << ", str() = \"" << out.str() << "\"\n"; std::ostringstream ate("1 2", std::ios_base::ate); ate << 3; std::cout << "After writing the int '3' to append stream \"1 2\"" << ", str() = \"" << ate.str() << "\"\n"; }
Sortie :
After reading the first int from "1 2", the int is 1, str() = "1 2" After writing the int '3' to output stream "1 2", str() = "3 2" After writing the int '3' to append stream "1 2", str() = "1 23"
Voir aussi
|
renvoie l'objet de périphérique de chaîne brut sous-jacent
(fonction membre publique) |
|
|
remplace ou obtient une copie de la chaîne de caractères associée
(fonction membre publique de
std::basic_stringbuf<CharT,Traits,Allocator>
)
|