basic_istream& operator>>( unsigned short& value );
(1)basic_istream& operator>>( unsigned int& value );
(2)basic_istream& operator>>( long& value );
(3)basic_istream& operator>>( unsigned long& value );
(4)basic_istream& operator>>( long long& value );
(5) (since C++11)basic_istream& operator>>( unsigned long long& value );
(6) (since C++11)basic_istream& operator>>( float& value );
(7)basic_istream& operator>>( double& value );
(8)basic_istream& operator>>( long double& value );
(9)basic_istream& operator>>( bool& value );
(10)basic_istream& operator>>( void*& value );
(11)basic_istream& operator>>( short& value );
(12)basic_istream& operator>>( int& value );
(13)basic_istream& operator>>( /* extended-floating-point-type */& value );
(14) (since C++23) (15) (16)basic_istream& operator>>( basic_istream& (*func)(basic_istream&) );
(17) (18)Extracts values from an input stream.
1-11) Extracts a value potentially skipping preceding whitespace. The value is stored to a given reference value.
12) Extracts a short value potentially skipping preceding whitespace. The value is stored to a given reference value.
13) Extracts an int value potentially skipping preceding whitespace. The value is stored to a given reference value.
14)Extracts an extended floating-point value potentially skipping preceding whitespace. The value is stored to a given reference
value. The library provides overloads for all cv-unqualified
extended floating-point typesas the referenced type of the parameter
value.
Determines the standard floating-point type
FP
as follows:
FP
is float.FP
is double.FP
is long double.This function behaves as a
FormattedInputFunction. After constructing and checking the sentry object, which may skip leading whitespace, extracts an
FP
value
fvalby calling
std::num_get::get(). After that:
failbit
and stores -std::numeric_limits</* extended-floating-point-type */>::max() to val.failbit
and stores std::numeric_limits</* extended-floating-point-type */>::max() to val.15-17) Calls func(*this), where func is an I/O manipulator.
18)Behaves as an
UnformattedInputFunction. After constructing and checking the sentry object, extracts all data from
*thisand stores it to
sb. The extraction stops if one of the following conditions are met:
failbit
is enabled in exceptions()
).In either case, stores the number of characters extracted in the member variable accessed by subsequent calls to
gcount(). If
sbis a null pointer or if no characters were inserted into
sb, calls
setstate(failbit)(which may throw
std::ios_base::failureif enabled).
If extraction fails (e.g. if a letter was entered where a digit is expected), zero is written to value and failbit
is set. For signed integers, if extraction results in the value too large or too small to fit in value, std::numeric_limits<T>::max() or std::numeric_limits<T>::min() (respectively) is written and failbit
flag is set. For unsigned integers, if extraction results in the value too large or too small to fit in value, std::numeric_limits<T>::max() is written and failbit
flag is set.
1-16,18) *this
17) func(*this)
[edit] NotesFor overload (14), when the extended floating-point type has a floating-point conversion rank that is not equal to the rank of any standard floating-point type, then double rounding during the conversion can result in inaccurate results. std::from_chars() can be used in situations where maximum accuracy is important.
[edit] Example#include <iomanip> #include <iostream> #include <sstream> int main() { std::string input = "41 3.14 false hello world"; std::istringstream stream(input); int n; double f; bool b; stream >> n >> f >> std::boolalpha >> b; std::cout << "n = " << n << '\n' << "f = " << f << '\n' << "b = " << std::boolalpha << b << '\n'; // extract the rest using the streambuf overload stream >> std::cout.rdbuf(); std::cout << '\n'; }
Output:
n = 41 f = 3.14 b = false hello world[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 64 C++98 it was unclear whether overload (18) can only rethrow theRetroSearch 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