I/O manipulators | ||||
Print functions(C++23) | ||||
C-style I/O | ||||
Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
Streams | ||||
Abstractions | ||||
File I/O | ||||
String I/O | ||||
Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
Synchronized Output | ||||
(C++20) | ||||
Types | ||||
Error category interface | ||||
(C++11) | ||||
(C++11) |
Global objects | ||||
Member functions | ||||
(C++11) | ||||
Formatted input | ||||
Unformatted input | ||||
Positioning | ||||
Miscellaneous | ||||
(C++11) | ||||
Member classes | ||||
Non-member functions | ||||
operator>>(std::basic_istream) |
Defined in header <istream> | ||
template<class CharT,class Traits> basic_istream<CharT, Traits>& | (1) | |
(2) | ||
template<class CharT,class Traits> basic_istream<CharT, Traits>& | (until C++20) | |
template<class CharT,class Traits,std::size_t N> basic_istream<CharT, Traits>& | (since C++20) | |
template<class Istream,class T> Istream&& | (3) | (since C++11) |
ch
. If no character is available, setsfailbit (in addition toeofbit that is set as required of aFormattedInputFunction).s
. The extraction stops if any of the following conditions is met:
| (until C++20) |
| (since C++20) |
Istream
is a class type publicly and unambiguously derived fromstd::ios_base.Contents |
Extracting a single character that is the last character of the stream does not seteofbit
: this is different from other formatted input functions, such as extracting the last integer withoperator>>, but this behavior matches the behavior ofstd::scanf with"%c" format specifier.
st | - | input stream to extract the data from |
ch | - | reference to a character to store the extracted character to |
s | - | pointer to(until C++20) a character array to store the extracted characters to |
#include <iomanip>#include <iostream>#include <sstream> int main(){std::string input="n greetings";std::istringstream stream(input); char c;constint MAX=6;char cstr[MAX]; stream>> c>>std::setw(MAX)>> cstr;std::cout<<"c = "<< c<<'\n'<<"cstr = "<< cstr<<'\n'; double f;std::istringstream("1.23")>> f;// rvalue stream extractionstd::cout<<"f = "<< f<<'\n';}
Output:
c = ncstr = greetf = 1.23
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 13 | C++98 | the definition ofn mentioned a non-existing nameeos | replaced withCharT() |
LWG 68 | C++98 | no null characters were stored at the end of the output for overload (2) | stores a null character |
LWG 1203 | C++98 | overload for rvalue stream returned lvalue reference to the base class | returns rvalue reference to the derived class |
LWG 2328 | C++98 | overload for rvalue stream required another argument to be lvalue | made to accept rvalue |
LWG 2534 | C++98 | overload for rvalue stream was not constrained | constrained |
extracts formatted data (public member function)[edit] |