Convert Octal String to Integer using stoi() Function in C++ STL
The octal numeral system, or oct for short, is the base-8 number system and uses the digits 0 to 7, that is to say, 10 octal represents eight, and 100 octal represents sixty-four.
How to Convert Octal String To Integer in C++?
We can use an in-built library function stoi() which stands for String to Integer. This is a Standard Library Function. stoi() function is used to convert a given string of any format is it binary, or octal that string can be converted to an integer.
int num = stoi(string_variable_name, [size_t* i] , int base);
- string_variable_name: It is the input string.
- size t* i: It is an optional parameter (pointer to the object whose value is set by the function), its default value is 0, or we can assign it to nullptr.
- int base: specifies the radix to determine the value type of the input string. Its default value is 10, it is also an optional parameter. For Octal its value is 8.
Return Value: This STL function returns an integer value.
Octal string: 124570 number: 43384
Octal string: 54689 number: 358
My Personal Notes arrow_drop_up
Please Login to comment...