| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
num_get::getnum_get::do_get |
| (1) | ||
public: iter_type get( iter_type in, iter_type end,std::ios_base& str, | ||
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,longlong& v)const; | (since C++11) | |
iter_type get( iter_type in, iter_type end,std::ios_base& str, std::ios_base::iostate& err,unsignedshort& v)const; | ||
iter_type get( iter_type in, iter_type end,std::ios_base& str, std::ios_base::iostate& err,unsignedint& v)const; | ||
iter_type get( iter_type in, iter_type end,std::ios_base& str, std::ios_base::iostate& err,unsignedlong& v)const; | ||
iter_type get( iter_type in, iter_type end,std::ios_base& str, std::ios_base::iostate& err,unsignedlonglong& v)const; | (since C++11) | |
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,longdouble& v)const; | ||
iter_type get( iter_type in, iter_type end,std::ios_base& str, std::ios_base::iostate& err,void*& v)const; | ||
| (2) | ||
protected: virtual iter_type do_get( iter_type in, iter_type end,std::ios_base& str, | ||
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,longlong& v)const; | (since C++11) | |
virtual iter_type do_get( iter_type in, iter_type end,std::ios_base& str, std::ios_base::iostate& err,unsignedshort& v)const; | ||
virtual iter_type do_get( iter_type in, iter_type end,std::ios_base& str, std::ios_base::iostate& err,unsignedint& v)const; | ||
virtual iter_type do_get( iter_type in, iter_type end,std::ios_base& str, std::ios_base::iostate& err,unsignedlong& v)const; | ||
virtual iter_type do_get( iter_type in, iter_type end,std::ios_base& str, std::ios_base::iostate& err, | (since C++11) | |
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,longdouble& 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; | ||
do_get of the most derived class.Conversion occurs in three stages:
Contents |
| (until C++11) |
| (since C++11) |
in
Before the resolutions ofLWG issue 23 andLWG issue 696,v was left unchanged if an error occurs.
Before the resolution ofLWG issue 221, strings representing hexadecimal integers (e.g."0xA0") were rejected bydo_get(int) even if they are valid input tostrtol because stage 2 filters out characters'X' and'x'.
Before the resolution ofLWG issue 1169, converting a negative number string into an unsigned integer might produce zero (since the value represented by the string is smaller than what the target type can represent).
Before the resolution ofLWG issue 2381, strings representing hexadecimal floating-point numbers with exponents (e.g."0x1.23p-10") were rejected by The strings representing infinity or not-a-number (e.g."NaN" and"inf") are rejected by | (since C++11) |
An implementation ofoperator>> for a user-defined type.
#include <iostream>#include <iterator>#include <locale> struct base{long x;}; template<class CharT,class Traits>std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, base& b){std::ios_base::iostate err=std::ios_base::goodbit; try// setting err could throw{typenamestd::basic_istream<CharT, Traits>::sentry s(is); if(s)// if stream is ready for inputstd::use_facet<std::num_get<CharT>>(is.getloc()).get(is,{}, is, err, b.x);}catch(std::ios_base::failure& error){// handle the exception} return is;} int main(){ base b;std::cin>> b;}
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 17 | C++98 | the process of parsing text boolean values was errornous | corrected |
| LWG 18 | C++98 | the overload ofget takingbool& value was missing | added |
| LWG 23 | C++98 | overflowing input resulted in undefined behavior | overflow handled |
| LWG 154 | C++98 | the conversion specifier fordouble was%g (same asfloat) | changed to%lg |
| LWG 221 | C++98 | do_get did not parse'x' and'X' whilestrtol parsed them | made'x' and'X' parsed |
| LWG 275 | C++98 | get had an overload takingshort& value instead offloat& | corrected |
| LWG 358 | C++98 | thousand separators after the decimal point were ignored | stage 2 is terminated if encountered |
| LWG 696 | C++98 | the result was unchanged on conversion failure | set to zero |
| LWG 1169 | C++98 | overflow handling was inconsistent between floating-point types | made consistent with strtof/strtod |
| LWG 2381 | C++11 | do_get did not parse'p' and'P' whilestrtod parsed them | made'p' and'P' parsed |
| extracts formatted data (public member function of std::basic_istream<CharT,Traits>)[edit] |