# std::from_chars

< cpp‎ | utility

C++
 Language Headers Freestanding and hosted implementations Named requirements Language support library Concepts library (C++20) Diagnostics library Utilities library Strings library Containers library Algorithms library Iterators library Numerics library Input/output library Localizations library Regular expressions library (C++11) Atomic operations library (C++11) Thread support library (C++11) Filesystem library (C++17) Technical Specifications

Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Library feature-test macros
Date and time
Function objects
(C++11)
Relational operators (deprecated)
Comparisons (C++20)
Common vocabulary types
 pair tuple(C++11) apply(C++17) make_from_tuple(C++17)
 optional(C++17) any(C++17) variant(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Elementary string conversions
(C++17)
from_chars
(C++17)
Type operations
(C++11)
(C++17)

 Defined in header  std::from_chars_result from_chars(const char* first, const char* last,                                   /*see below*/& value, int base = 10); (1) (since C++17) std::from_chars_result from_chars(const char* first, const char* last, float& value,                                   std::chars_format fmt = std::chars_format::general); (2) (since C++17) std::from_chars_result from_chars(const char* first, const char* last, double& value,                                   std::chars_format fmt = std::chars_format::general); (3) (since C++17) std::from_chars_result from_chars(const char* first, const char* last, long double& value,                                   std::chars_format fmt = std::chars_format::general); (4) (since C++17) struct from_chars_result {     const char* ptr;     std::errc ec; }; (5) (since C++17)

Analyzes the character sequence [first,last) for a pattern described below. If no characters match the pattern or if the value obtained by parsing the matched characters is not representable in the type of value, value is unmodified, otherwise the characters matching the pattern are interpreted as a text representation of an arithmetic value, which is stored in value.

1) Integer parsers: Expects the pattern identical to the one used by std::strtol in the default ("C") locale and the given non-zero numeric base, except that "0x" or "0X" prefixes are not recognized for base 16, and that only the minus sign is recognized (not the plus sign), and only for signed integer types of value. Digits in the range 10..35 (inclusive) are represented as lowercase characters a..z (uppercase digits are not recognized). The library provides overloads for all signed and unsigned integer types and char as the referenced type of the parameter value.
2-4) Floating-point parsers: Expects the pattern identical to the one used by std::strtod in the default ("C") locale, except that
In any case, the resulting value is one of at most two floating-point values closest to the value of the string matching the pattern, after rounding according to std::round_to_nearest.
5) The return type (see Return value below)

### Parameters

 first, last - valid character range to parse value - the out-parameter where the parsed value is stored if successful base - integer base to use: a value between 2 and 36 (inclusive). fmt - floating-point formatting to use, a bitmask of type std::chars_format

### Return value

On success, returns a value of type from_chars_result such that ptr points at the first character not matching the pattern, or has the value equal to last if all characters match and ec is value-initialized.

If there is no pattern match, returns a value of type from_chars_result such that ptr equals first and ec equals std::errc::invalid_argument. value is unmodified.

If the pattern was matched, but the parsed value is not in the range representable by the type of value, returns value of type from_chars_result such that ec equals std::errc::result_out_of_range and ptr points at the first character not matching the pattern. value is unmodified.

(none)
{"ft_lang_label":"__label__en","ft_lang_prob":0.72062624,"math_prob":0.93325883,"size":4567,"snap":"2021-21-2021-25","text_gpt3_token_len":1109,"char_repetition_ratio":0.1503397,"word_repetition_ratio":0.115326256,"special_character_ratio":0.2520254,"punctuation_ratio":0.17213115,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95192087,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-06-24T00:29:52Z\",\"WARC-Record-ID\":\"<urn:uuid:315c3b20-a708-4f83-8b85-9c4ef87ea0fb>\",\"Content-Length\":\"41627\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4a665b1c-58d5-4f16-a495-3539fbe6bb3f>\",\"WARC-Concurrent-To\":\"<urn:uuid:458b8f27-e171-4bd0-ac4f-75e305a59f66>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"https://doc.hc2.ch/c_cpp/en/cpp/utility/from_chars.html\",\"WARC-Payload-Digest\":\"sha1:ZFLNV76WSVFJGTEDTZWSAEZUFKVDTGHI\",\"WARC-Block-Digest\":\"sha1:6FQ3TP3O2HPASF2G6Q5BTHU7P7P5TG5W\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-25/CC-MAIN-2021-25_segments_1623488544264.91_warc_CC-MAIN-20210623225535-20210624015535-00049.warc.gz\"}"}