Namespaces
Variants

std::basic_ostringstream<CharT,Traits,Allocator>:: basic_ostringstream

From cppreference.net

(Anmerkung: Der bereitgestellte HTML-Code enthält keinen übersetzbaren Text, da alle Tags leer sind. Die Struktur bleibt unverändert, wie angefordert.)
(1)
explicit basic_ostringstream ( std:: ios_base :: openmode mode =
std:: ios_base :: out ) ;
(bis C++11)
explicit basic_ostringstream ( std:: ios_base :: openmode mode ) ;
(seit C++11)
basic_ostringstream ( )
: basic_ostringstream ( std:: ios_base :: out ) { }
(2) (seit C++11)
explicit basic_ostringstream

( const std:: basic_string < CharT, Traits, Allocator > & str,
std:: ios_base :: openmode mode =

std:: ios_base :: out ) ;
(3)
explicit basic_ostringstream

( std:: basic_string < CharT, Traits, Allocator > && str,
std:: ios_base :: openmode mode =

std:: ios_base :: out ) ;
(4) (seit C++20)
basic_ostringstream ( std:: ios_base :: openmode mode, const Allocator & a ) ;
(5) (seit C++20)
template < class SAlloc >

basic_ostringstream ( const std:: basic_string < CharT, Traits, SAlloc > & str,

std:: ios_base :: openmode mode, const Allocator & a ) ;
(6) (seit C++20)
template < class SAlloc >

basic_ostringstream ( const std:: basic_string < CharT, Traits, SAlloc > & str,
const Allocator & a )

: basic_ostringstream ( str, std:: ios_base :: out , a ) { }
(7) (seit C++20)
template < class SAlloc >

explicit basic_ostringstream
( const std:: basic_string < CharT, Traits, SAlloc > & str,
std:: ios_base :: openmode mode =

std:: ios_base :: out ) ;
(8) (seit C++20)
template < class StringViewLike >

explicit basic_ostringstream
( const StringViewLike & t,
std:: ios_base :: openmode mode =

std:: ios_base :: out ) ;
(9) (seit C++26)
template < class StringViewLike >

basic_ostringstream ( const StringViewLike & t,

std:: ios_base :: openmode mode, const Allocator & a ) ;
(10) (seit C++26)
template < class StringViewLike >
basic_ostringstream ( const StringViewLike & t, const Allocator & a ) ;
(11) (seit C++26)
basic_ostringstream ( basic_ostringstream && other ) ;
(12) (seit C++11)

Konstruiert einen neuen String-Stream.

Gegeben

die std::basic_ostream Basis und das Ausstellungs-exklusive Datenmitglied sb werden wie folgt initialisiert.

Überladung
(Overload)
std::basic_ostream Basis 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) Move-konstruiert aus other 's std::basic_ostream Basis Move-konstruiert aus other. sb
  1. Die std::basic_iostream Basis wurde initialisiert mit base_type ( & sb ) (für Überladungen (1,3) ) bis C++11.
8) Diese Überladung nimmt nur dann an der Überladungsauflösung teil, wenn std:: is_same_v < SAlloc, Allocator > false ist.
9-11) Diese Überladungen nehmen an der Überladungsauflösung nur teil, wenn std:: is_convertible_v < const StringViewLike & , std:: basic_string_view < CharT, Traits >> gleich true ist.

Inhaltsverzeichnis

Parameter

str - Zeichenkette, die als initialer Inhalt des String-Streams verwendet wird
t - ein Objekt (konvertierbar zu std::basic_string_view ), das als initialer Inhalt des String-Streams verwendet wird
a - Allokator, der für die Zuweisung des Inhalts des String-Streams verwendet wird
mode - gibt den Stream-Öffnungsmodus an. Es handelt sich um einen BitmaskType , die folgenden Konstanten sind definiert:
Konstante Erklärung
app springt vor jedem Schreibvorgang zum Ende des Streams
binary öffnet im Binärmodus
in öffnet zum Lesen
out öffnet zum Schreiben
trunc verwirft den Inhalt des Streams beim Öffnen
ate springt unmittelbar nach dem Öffnen zum Ende des Streams
noreplace (C++23) öffnet im exklusiven Modus
other - ein weiterer String-Stream, der als Quelle verwendet wird

Hinweise

Die Konstruktion von einmalig verwendeten basic_ostringstream Objekten in einer engen Schleife, wie sie beispielsweise für String-Konvertierungen verwendet wird, kann erheblich teurer sein als der Aufruf von str() zur Wiederverwendung desselben Objekts.

Feature-Test Makro Wert Std Funktion
__cpp_lib_sstream_from_string_view 202306L (C++26) Verbindung von std::stringstream mit std::string_view , ( 9-11 )

Beispiel

#include <iostream>
#include <sstream>
int main()
{
    // Standardkonstruktor (Eingabe/Ausgabe-Stream)
    std::stringstream buf1;
    buf1 << 7;
    int n = 0;
    buf1 >> n;
    std::cout << "buf1 = " << buf1.str() << " n = " << n << '\n';
    // Eingabe-Stream
    std::istringstream inbuf("-10");
    inbuf >> n;
    std::cout << "n = " << n << '\n';
    // Ausgabe-Stream im Anhänge-Modus (C++11)
    std::ostringstream buf2("test", std::ios_base::ate);
    buf2 << '1';
    std::cout << buf2.str() << '\n';
}

Ausgabe:

buf1 = 7 n = 7
n = -10
test1

Fehlerberichte

Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.

DR Angewendet auf Verhalten wie veröffentlicht Korrektes Verhalten
P0935R0 C++11 der Standardkonstruktor war explicit implizit gemacht

Siehe auch

ruft den Inhalt des zugrundeliegenden String-Device-Objekts ab oder setzt ihn
(öffentliche Elementfunktion)
konstruiert ein basic_stringbuf -Objekt
(öffentliche Elementfunktion von std::basic_stringbuf<CharT,Traits,Allocator> )