Namespaces
Variants

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

From de.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)
(bis C++11)
explicit basic_stringstream ( std:: ios_base :: openmode mode ) ;
(seit C++11)
basic_stringstream ( )
: basic_stringstream ( std:: ios_base :: in | std:: ios_base :: out ) { }
(2) (seit C++11)
explicit basic_stringstream

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

std:: ios_base :: in | std:: ios_base :: out ) ;
(3)
explicit basic_stringstream

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

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

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

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

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

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

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

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

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

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

basic_stringstream ( const StringViewLike & t,

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

Konstruiert einen neuen String-Stream.

Gegeben

die std::basic_iostream Basis und das exposition-only data member sb werden wie folgt initialisiert.

Über
ladung
std::basic_iostream Basis sb
(1) base_type ( std:: addressof ( sb ) ) [1] buf_type ( mode )
(2) buf_type ( std:: ios_base :: in | std:: ios_base :: out )
(3) buf_type ( str, mode )
(4) buf_type ( std :: move ( str ) , mode )
(5) buf_type ( mode, a )
(6) buf_type ( str, mode, a )
(7) buf_type ( str, std:: ios_base :: in | std:: ios_base :: out , a )
(8) buf_type ( str, mode )
(9) std:: addressof ( sb ) { t, mode, Allocator ( ) }
(10) { t, mode, a }
(11) { t, std:: ios_base :: in | std:: ios_base :: out , a }
(12) Move-konstruiert aus other 's std::basic_iostream 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 nur dann an der Überladungsauflösung teil, wenn std:: is_convertible_v < const StringViewLike & , std:: basic_string_view < CharT, Traits >> 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 der Inhalte 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 die Inhalte 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_stringstream Objekten in einer engen Schleife, wie sie beispielsweise für String-Konvertierung verwendet wird, kann deutlich kostspieliger sein als der Aufruf von str() zur Wiederverwendung desselben Objekts.

Feature-Test Makro Wert Std Feature
__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-/Ausgabestream)
    std::stringstream buf1;
    buf1 << 7;
    int n = 0;
    buf1 >> n;
    std::cout << "buf1 = " << buf1.str() << " n = " << n << '\n';
    // Eingabestream
    std::istringstream inbuf("-10");
    inbuf >> n;
    std::cout << "n = " << n << '\n';
    // Ausgabestream im Anhängemodus (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> )