Note that std::stoi("-0x77") yields 0 because it parses only -0, interpreting the x as the end of the numeric value found. Note that std::stol("789",&idx,8) parses only the first character of the string because 8 is not a valid character for octal numbers.