Originally Posted by
jimblumberg
Exactly how does it fail?
No, hexadecimals are preceded by "0x" an integer starting with zero is assumed to be an Octal number.
No, as long as the letter is in the range of valid hexadecimal ( A - F or a - f) and the converted number is within the range for the type, it should still convert the number correctly.
try compiling:
Code:
int main() {
std::string foo = "a0001, A Space Odyssey";
int foo_int = std::stoi(foo, nullptr, 10);
std::cout << foo_int;
return 0;
}
when using hexadecimal (base 16):
Code:
int main() {
std::string foo = "g0001, A Space Odyssey"; //"a0001, A Space Odyssey" does not throw that error but that's not what we want here.
int foo_int = std::stoi(foo, nullptr, 16);
std::cout << foo_int;
return 0;
}
both of them give you a "Debug Error!" ... "abort() has been called"
Turns out you're right the compiler will still treat "a0001, A Space Odyssey" as a hexadecimal, even though it is not preceded by "0x" (0x, like you mentioned and thanks for correcting me). So OldGuy2 would have been right if my question were that I was not able to pass Hexadecimal values but that's not what I want.
By the way is there an overloaded function for stoi() that I don't know about as OldGuy2 mentioned?
Oh and here is the error I get while trying to compile the mentioned:
Oh and I just realized there are two smiley faces representing the same symbol ([B]:p[/B] and [B]:tongue: [/B].. weird!)