std::num_get<CharT,InputIt>::get,std::num_get<CharT,InputIt>::do_get (3) - Linux Man Pages
std::num_get<CharT,InputIt>::get,std::num_get<CharT,InputIt>::do_get: std::num_get<CharT,InputIt>::get,std::num_get<CharT,InputIt>::do_get
NAME
std::num_get<CharT,InputIt>::get,std::num_get<CharT,InputIt>::do_get - std::num_get<CharT,InputIt>::get,std::num_get<CharT,InputIt>::do_get
Synopsis
public:
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, bool& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, long& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, long long& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, unsigned short& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, unsigned int& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, unsigned long& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, unsigned long long& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, float& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, double& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, long double& v ) const;
iter_type get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, void*& v ) const; (1)
protected:
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, bool& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, long& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, long long& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, unsigned short& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, unsigned int& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str, (2)
std::ios_base::iostate& err, unsigned long& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, unsigned long long& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, float& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, double& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, long double& v ) const;
virtual iter_type do_get( iter_type in, iter_type end, std::ios_base& str,
std::ios_base::iostate& err, void*& v ) const;
1) Public member function, calls the member function do_get of the most derived class.
2) Reads characters from the input iterator in and generates the value of the type of v, taking into account IO stream formatting flags from str.flags(), character classification rules from std::use_facet<std::ctype<charT>>(str.getloc()), and numeric punctuation characters from std::use_facet<std::numpunct<charT>>(str.getloc()). This function is called by all formatted input stream operators such as std::cin >> n;.
Conversion occurs in three stages
Stage 1: conversion specifier selection
* I/O format flags are obtained, as if by
* If the type of v is an integer type, the the first applicable choice of the following five is selected:
* For integer types, length modifier is added to the conversion specification if necessary: h for short and unsigned short, l for long and unsigned long, ll for long long and unsigned long long
* If the type of v is float, will use conversion specifier %g
* If the type of v is double, will use conversion specifier %lg
* If the type of v is long double, will use conversion specifier %Lg
* If the type of v is void*, will use conversion specifier %p
* If the type of v is bool and boolalpha==0, proceeds as if the type of v is long, except for the value to be stored in v in stage 3.
* If the type of v is bool and boolalpha!=0, the following replaces stages 2 and 3:
Stage 2: character extraction
* If in==end, Stage 2 is terminated immediately, no further characters are extracted
* The next character is extracted from in as if by char_type ct = *in;
Stage 3: conversion and storage
* The sequence of chars accumulated in Stage 2 is converted to a numeric value
* If the conversion function fails to convert the entire field, the value 0 is stored in v
* If the conversion function results in a positive value too large to fit in the type of v, the most positive representable value is stored in v
* If the conversion function results in a negative value too large to fit in the type of v, the most negative representable value is stored in v (since C++11)
* In any case, if the conversion function fails std::ios_base::failbit is assigned to err
* Otherwise, the numeric result of the conversion is stored in v
* After this, digit grouping is checked. if the position of any of the thousands separators discarded in Stage 2 does not match the grouping provided by std::use_facet<std::numpunct<charT>>(str.getloc()).grouping(), std::ios_base::failbit is assigned to err.
* If Stage 2 was terminated by the test in==end, err|=std::ios_base::eofbit is executed to set the eof bit.
Return value
in
Notes
In C++98/C++03, if an error occurs, v is left unchanged. In C++11, it is set to a value as described above.
The result of converting a negative number string into an unsigned integer was specified to produce zero until C++17, although some implementations followed the protocol of std::strtoull which negates in the target type, giving ULLONG_MAX for "-1", and so produce the largest value of the target type instead. As of C++17, strictly following std::strtoull is the correct behavior.
Because stage 2 filters out characters such as 'p', 'N' or 'i', the hexadecimal floating-point numbers such as "0x1.23p-10" and the strings "NaN" or "inf" may be rejected by do_get(double) even if they are valid input to strtod: this is LWG_#2381
Example
An implementation of operator>> for a user-defined type.
// Run this code
See also
operator>> (public member function of std::basic_istream<CharT,Traits>)