std::basic_istringstream<CharT,Traits,Allocator>:: basic_istringstream
| (1) | ||
|
explicit
basic_istringstream
(
std::
ios_base
::
openmode
mode
=
std:: ios_base :: in ) ; |
(bis C++11) | |
|
explicit
basic_istringstream
(
std::
ios_base
::
openmode
mode
)
;
|
(seit C++11) | |
|
basic_istringstream
(
)
: basic_istringstream ( std:: ios_base :: in ) { } |
(2) | (seit C++11) |
|
explicit
basic_istringstream
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
str,
|
(3) | |
|
explicit
basic_istringstream
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
str,
|
(4) | (seit C++20) |
|
basic_istringstream
(
std::
ios_base
::
openmode
mode,
const
Allocator
&
a
)
;
|
(5) | (seit C++20) |
|
template
<
class
SAlloc
>
basic_istringstream
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
str,
|
(6) | (seit C++20) |
|
template
<
class
SAlloc
>
basic_istringstream
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
str,
|
(7) | (seit C++20) |
|
template
<
class
SAlloc
>
explicit
basic_istringstream
|
(8) | (seit C++20) |
|
template
<
class
StringViewLike
>
explicit
basic_istringstream
|
(9) | (seit C++26) |
|
template
<
class
StringViewLike
>
basic_istringstream
(
const
StringViewLike
&
t,
|
(10) | (seit C++26) |
|
template
<
class
StringViewLike
>
basic_istringstream ( const StringViewLike & t, const Allocator & a ) ; |
(11) | (seit C++26) |
|
basic_istringstream
(
basic_istringstream
&&
other
)
;
|
(12) | (seit C++11) |
Konstruiert einen neuen String-Stream.
Gegeben
-
base_typeals std:: basic_istream < CharT, Traits > , und -
buf_typeals std:: basic_stringbuf < CharT, Traits, Allocator > ,
die
std::basic_istream
Basis und das
exposition-only data member
sb
werden wie folgt initialisiert.
|
Überladung
(Overload) |
std::basic_istream Basis |
sb
|
|---|---|---|
| (1) | base_type ( std:: addressof ( sb ) ) [1] | buf_type ( mode | std:: ios_base :: in ) |
| (2) | buf_type ( std:: ios_base :: in ) | |
| (3) | buf_type ( str, mode | std:: ios_base :: in ) | |
| (4) | buf_type ( std :: move ( str ) , mode | std:: ios_base :: in ) | |
| (5) | buf_type ( mode | std:: ios_base :: in , a ) | |
| (6) | buf_type ( str, mode | std:: ios_base :: in , a ) | |
| (7) | buf_type ( str, std:: ios_base :: in , a ) | |
| (8) | buf_type ( str, mode | std:: ios_base :: in ) | |
| (9) | std:: addressof ( sb ) | { t, mode | std:: ios_base :: in , Allocator ( ) } |
| (10) | { t, mode | std:: ios_base :: in , a } | |
| (11) | { t, std:: ios_base :: in , a } | |
| (12) | Move-konstruiert aus other 's std::basic_istream Basis | Move-konstruiert aus other. sb |
- ↑ Die std::basic_iostream Basis wurde initialisiert mit base_type ( & sb ) (für Überladungen (1,3) ) bis C++11.
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:
|
||||||||||||||||
| other | - | ein weiterer String-Stream, der als Quelle verwendet wird |
Hinweise
Die Konstruktion von einmalig verwendeten
basic_istringstream
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 | 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 die Inhalte des zugrundeliegenden String-Device-Objekts ab oder setzt sie
(öffentliche Elementfunktion) |
|
konstruiert ein
basic_stringbuf
-Objekt
(öffentliche Elementfunktion von
std::basic_stringbuf<CharT,Traits,Allocator>
)
|