The following program
#include <charconv>
#include <string>
#include <iostream>
int main() {
std::string s = "0X1.BC70A3D70A3D7P+6";
std::cout << "strtod: " << std::strtod(s.c_str(), nullptr) << std::endl;
double d = 42;
std::from_chars(s.data(), s.data() + s.size(), d, std::chars_format::general);
std::cout << "from_chars: " << d << std::endl;
}
prints
strtod: 111.11
from_chars: 0
when compiled with GCC on Linux. Can std::from_chars not handle hexadecimal floating-point numbers?
std::from_charsit doesn't handle the leading0X.std::chars_format::hexif I understood that documentation correctlyif fmt is std::chars_format::hex, the prefix "0x" or "0X" is not permitted (the string "0x123" parses as the value "0" with unparsed remainder "x123")std::chars_format::generalexpects the string to be in%gformat. That's not a hex format.