Sample below:
string s1 = "abcde";
string s2(s1, s1.size()); // s1.size() = 5.
Notice that s1.size() = 5 and the last allowable index = 4 (for character 'e'). The above runs fine returning empty string. Only when pos = 6 then it fail with exception out-of-range. Why?
According to cppereference site:
Exceptions
3) std::out_of_range if pos > other.size()
Shouldn't the correct exception be "if pos >= other.size()"?