![]() |
VOOZH | about |
The strtol() function is a builtin function in C++ STL which converts the contents of a string as an integral number of the specified base and return its value as a long int. Syntax:
strtol(s, &end, b)
Parameters: The function accepts three mandatory parameters which are described as below:
Return Value: The function returns value of two types:
Below programs illustrate the above function. Program 1:
Number in String = 6010IG_2016p Number in Long Int = 6010 End String = IG_2016p Number in String = 47 Number in Long Int = 47 Null pointer
Program 2:
489bc to Long Int with base-4 = 0 End String = 489bc 123s to Long Int with base-11 = 146 End String = s 56xyz to Long Int with base-36 = 8722043
Program 3:
312gfg to Long Int with base-0 = 312 End String = gfg 0q15axtz to Long Int with base-0 = 0 End String = q15axtz 33ffn to Long Int with base-0 = 33 End String =
Program 4
22abcd to Long Int with base-6 = 14 End String = abcd 114cd to Long Int with base-2 = 3 End String = 4cd e10.79 to Long Int with base-10 = 0 End String = e10.79