Search⌘ K

to_chars

Explore the to_chars function in C++17 for efficient string conversions of integers and floating point numbers. Understand how to specify output formats, manage precision, and interpret the conversion results including error handling.

to_chars is a set of overloaded functions for integral and floating point types.

Integral types declaration

C++
std::to_chars_result to_chars(char* first, char* last, TYPE value, int base = 10);

Where TYPE expands to all available signed and unsigned integer types and char.

Since base might range from 2 to 36, the output digits that are greater than 9 are represented as lowercase letters: a...z.

Floating point types declaration

Basic function

C++
std::to_chars_result to_chars(char* first, char* last, FLOAT_TYPE value);

FLOAT_TYPE expands to float ...