Strtol is a C-language function that converts a string to a long integer, whose function prototype is:
Long int strtol (constcharcharintbase);
Let's look at the meaning of each parameter:
STR is the character to convert
Enptr is a pointer to the first non-convertible character position
Base base, which represents the number of conversions to a binary
Two points Note:
- When the value of base is 0 o'clock, the default is 10-in conversion, but if the ' 0x '/' 0X ' pre-character is used with a 16-binary conversion, the ' 0 ' pre-character will be converted using the 8-in-place.
- If endptr is not null, the character pointer that terminates the encountered non-conforming condition is passed back by endptr, or if the endptr is null, the parameter is invalid or not used.
string " 1.10.2 " ; char *c = (char*) v.c_str (); Long Ten );p rintf ("%d\n", D);p rintf ("%s\n ", c);
This code first defines a value of "1.10.2" the string c, and then call Strtol, when the D is 1, the string C becomes ". 10.2" .
Resources:
Http://c.biancheng.net/cpp/html/129.html
Strtol function Usage