CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 28 Jul 2025 16:56:30 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/locale/num_get/get/
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 28 Jul 2025 16:56:30 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"a19c-Mr7df73Fpj54jO2CBGTIZED7eLA"
Content-Encoding: gzip
Parses the sequence of characters between in and end for a numerical value, and stores it into v. For the process, it uses the formatting options selected in str (using its ios_base::fmtflags value), and updates err with the error status when necessary.
The function stops reading characters from the sequence as soon as one character cannot be part of a valid numerical expression (or end is reached). The next character in the sequence is pointed by the iterator returned by the function.
A ios_base::iostate bitmask value is stored in err with the result of the operation:
Internally, this function simply calls the virtual protected member do_get, which by default parses the numerical value following the same format as scanf does for the format specifier that corresponds to the type of argument val taking into account str's format flags. The function uses the locale selected in str to obtain format details (through facet numpunct) and to widen characters (with ctype::widen).
Member type iter_type is the facet's iterator type (defined as an alias of num_get's second template parameter, InputIterator).
Possible output:
Arguments str, err and val may be modified.
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
<locale>
- has_facet
- locale
- use_facet
-
wbuffer_convertC++11
-
wstring_convertC++11
functions
standard facets
num_get
- num_get::num_get
public member functions
protected members
public member function
<locale>
std::num_get::get
bool (1) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, bool& val) const; |
---|---|
long (2) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, long& val) const; |
unsigned short (3) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, unsigned short& val) const; |
unsigned int (4) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, unsigned int& val) const; |
unsigned long (5) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, unsigned long& val) const; |
float (6) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, float& val) const; |
double (7) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, double& val) const; |
long double (8) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, long double& val) const; |
pointer (9) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, void*& val) const; |
bool (1) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, bool& val) const; |
---|---|
long (2) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, long& val) const; |
unsigned short (3) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, unsigned short& val) const; |
unsigned int (4) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, unsigned int& val) const; |
unsigned long (5) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, unsigned long& val) const; |
float (6) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, float& val) const; |
double (7) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, double& val) const; |
long double (8) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, long double& val) const; |
pointer (9) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, void*& val) const; |
long long (10) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, long long& val) const; |
unsigned long long (11) | iter_type get (iter_type in, iter_type end, ios_base& str, ios_base::iostate& err, unsigned long long& val) const; |
Get numeric value
The function stops reading characters from the sequence as soon as one character cannot be part of a valid numerical expression (or end is reached). The next character in the sequence is pointed by the iterator returned by the function.
A ios_base::iostate bitmask value is stored in err with the result of the operation:
value in err | value in val | description |
---|---|---|
goodbit | the value read | Success (without reaching end). |
failbit | unspecified | Failure: The sequence of characters did not match the expected format |
eofbit | one of the above | end was reached during the operation (this can happen both in case of success or failure). |
value in err | value in val | description |
---|---|---|
unchanged | the value read | Success (without reaching end). |
failbit | zero | The sequence did not match the expected format |
numeric_limits::max() | The sequence represents a value too large for the type of val | |
numeric_limits::lowest() | The sequence represents a value too large negative for the type of val | |
eofbit | one of the above | end was reached during the operation (this can happen both in case of success or failure) |
Internally, this function simply calls the virtual protected member do_get, which by default parses the numerical value following the same format as scanf does for the format specifier that corresponds to the type of argument val taking into account str's format flags. The function uses the locale selected in str to obtain format details (through facet numpunct) and to widen characters (with ctype::widen).
Parameters
- in, end
- Iterators pointing to the beginning and end characters of the sequence. The range used is
[in,end)
, which contains all the characters between in and end, including the character pointed by in but not the character pointed by end.
Member type iter_type is the facet's iterator type (defined as an alias of num_get's second template parameter, InputIterator). By default, this is an istreambuf_iterator, allowing implicit conversions from basic_istream objects. - str
- Object of a class derived from ios_base (generally an input stream object). It is only used to obtain formatting information.
- err
- Stream error state object, of type ios_base::iostate where the resulting state is stored.
- val
- Element of a numerical type.
The function stores the value in it if it successfully extracts a number (i.e. if err's failbit flag is not set).
Return value
The next character in the sequence right after where the extraction operation ended.Member type iter_type is the facet's iterator type (defined as an alias of num_get's second template parameter, InputIterator).
Example
|
|
Possible output:
Please, enter PI: 3.14 Right! |
Data races
The object, and up to the entire range between in and end, are accessed.Arguments str, err and val may be modified.
Exception safety
If an exception is thrown, there are no changes in the facet object, although some of arguments may have been affected.See also
- num_put::put
- Put numerical value (public member function)
- istream::operator>>
- Extract formatted input (public member function)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us