The first parameter of the C ++ STL function substr (pos, n), pos, has this behavior.
"If the position passed past the end of the line, an out_of_range exception is thrown."
However, if I do something like
string s("ab"); cout<<s.substr(2,666)<<endl;
then no exception is thrown even if pos = 2 is by definition located beyond the end of the line.
The string :: end defines the position "after the last character in the string" as "minus the end of the string". I noticed that the returned character is always "\ 0". My question is that this is standard behavior, and if I can expect that in this case an empty string is returned. Thanks.
source share