+ 5
length is original length of the string you passed without any modification.
But PhBookLine.length() will decresed it's value since you are erasing characters from PhBookLine string. So it's PhBookLine.length() is each time calcuated in i<PhBookLine.length() so it's gets update value but length is calculated before loop and can't changed in loop so you access beyond length of string since you are erasing..
+ 3
int len = str.length() ;
If you change len value then it will change.
if you change Or erase from str, then it's str.length() will change.
They both, not point to same memory.. They are different values..
If you want update len then find again len = str.length() after earse..
+ 2
string s = "abcde";
int len = s.length() ;
cout<< len ; // 5
s.erase(1, 1) ;
cout << s.length() << " " << len ; // 4 5
s.erase(1, 1) ;
cout << s.length() << " " << len ; // 3 5
What is your task by code there?
+ 2
Yes.
Initially it's length is 57
After erase , length is 25 (=>length);
after end of loop : 13
+ 1
Yes.
Check both values initially it's 25 after it is 13
+ 1
Yes.
- 1
Hi
- 1
Hello