s.substr(0,p) The first argument is the starting position; the second is the length. If you omit the length, you get the longest possible substring with the given starting position, which is why s.substr(p+1) works.
* without arguments , a copy of the string itself is returned.
* The first argument may be used to specify the offset of the first character to be returned.
* The second argument may be used to specify the number of characters that are to be
Note that the second argument 'number of characters' it's not the offset index.
PS: C++ Annotations is a free OpenSource package.So I copied with free.