basic_istream<CharT, Traits>&
operator>>( basic_istream<CharT, Traits>& st, CharT& ch );
template< class Traits >
template< class Traits >
basic_istream<CharT, Traits>&
operator>>( basic_istream<CharT, Traits>& st, CharT* s );
template< class Traits >
template< class Traits >
basic_istream<CharT, Traits>&
operator>>( basic_istream<CharT, Traits>& st, CharT (&s)[N] );
template< class Traits, std::size_t N >
template< class Traits, std::size_t N >
Istream&&
1,2) Performs character input operations.
1)Behaves as a
FormattedInputFunction. After constructing and checking the sentry object, which may skip leading whitespace, extracts a character and stores it to
ch
. If no character is available, sets
failbit(in addition to
eofbitthat is set as required of a
FormattedInputFunction).
2)Behaves as a
FormattedInputFunction. After constructing and checking the sentry object, which may skip leading whitespace, extracts successive characters and stores them at successive locations of
a character array whose first element is pointed to by(until C++20)s
. The extraction stops if any of the following conditions is met:
In either case, an additional null character value
CharT()is stored at the end of the output. If no characters were extracted, sets
failbit(the null character is still written, to the first position in the output). Finally, calls
st.width(0)to cancel the effects of
std::setw, if any.
3)Calls the appropriate extraction operator, given an rvalue reference to an input stream object (equivalent to
st >> std::forward<T>(value)). This overload participates in overload resolution only if
st >> std::forward<T>(value)is well-formed and
Istream
is a class type publicly and unambiguously derived from
std::ios_base.
[edit] NotesExtracting a single character that is the last character of the stream does not set eofbit
: this is different from other formatted input functions, such as extracting the last integer with operator>>, but this behavior matches the behavior of std::scanf with "%c" format specifier.
1,2) st
3) std::move(st)
[edit] Example#include <iomanip> #include <iostream> #include <sstream> int main() { std::string input = "n greetings"; std::istringstream stream(input); char c; const int 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 extraction std::cout << "f = " << f << '\n'; }
Output:
c = n cstr = greet f = 1.23[edit] Defect reports
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 of n mentioned a non-existing name eos replaced with CharT() 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 referenceRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4