std::basic_ostringstream<CharT,Traits,Allocator>:: str
| (1) | ||
|
std::
basic_string
<
CharT, Traits, Allocator
>
str
(
)
const
;
|
(bis C++20) | |
|
std::
basic_string
<
CharT, Traits, Allocator
>
str
(
)
const
&
;
|
(seit C++20) | |
|
template
<
class
SAlloc
>
std:: basic_string < CharT, Traits, SAlloc > str ( const SAlloc & a ) const ; |
(2) | (seit C++20) |
|
std::
basic_string
<
CharT, Traits, Allocator
>
str
(
)
&&
;
|
(3) | (seit 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) | (seit C++20) |
|
void
str
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
s
)
;
|
(6) | (seit C++20) |
|
template
<
class
StringViewLike
>
void str ( const StringViewLike & t ) ; |
(7) | (seit C++26) |
Verwaltet den Inhalt des zugrundeliegenden String-Objekts.
Inhaltsverzeichnis |
Parameter
| s | - | neue Inhalte des zugrundeliegenden Strings |
| t | - | ein Objekt (konvertierbar zu std::basic_string_view ), das als neue Inhalte des zugrundeliegenden Strings verwendet wird |
| a | - | Allokator, der zur Konstruktion des zurückgegebenen Strings verwendet wird |
Rückgabewert
Hinweise
Die Kopie des zugrundeliegenden Strings, die von
str
zurückgegeben wird, ist ein temporäres Objekt, das am Ende des Ausdrucks zerstört wird. Daher führt das direkte Aufrufen von
c_str()
auf das Ergebnis von
str
(
)
(zum Beispiel in
auto
*
ptr
=
out.
str
(
)
.
c_str
(
)
;
) zu einem hängenden Zeiger.
| Feature-Test Makro | Wert | Std | Feature |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | Verbindung von std::stringstream mit std::string_view , ( 7 ) |
Beispiel
#include <iostream> #include <sstream> int main() { int n; std::istringstream in; // could also use 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"; }
Ausgabe:
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"
Siehe auch
|
gibt das zugrundeliegende Roh-String-Geräteobjekt zurück
(öffentliche Elementfunktion) |
|
|
ersetzt oder erhält eine Kopie des assoziierten Zeichenstrings
(öffentliche Elementfunktion von
std::basic_stringbuf<CharT,Traits,Allocator>
)
|