C++14
No; you can depend on it.
In 21.4.5.2 (or [string.access]) we can find:
Returns:
*(begin() + pos)
ifpos < size()
. Otherwise, returns a reference to an object of typecharT
with valuecharT()
, where modifying the object leads to undefined behavior.
In other words, when pos == size()
(which is true when both are 0), the operator will return a reference to a default-constructed character type which you are forbidden to modify.
It is not special-cased for the empty (or 0-sized) strings and works the same for every length.
C++03
And most certainly C++98 as well.
It depends.
Here’s 21.3.4.1 from the official ISO/IEC 14882:
Returns: If
pos < size()
, returnsdata()[pos]
. Otherwise, ifpos == size()
, the const version returnscharT()
. Otherwise, the behavior is undefined.