+ 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..
19th Jul 2022, 7:58 AM
Jayakrishna 🇮🇳
+ 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..
19th Jul 2022, 9:27 AM
Jayakrishna 🇮🇳
+ 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?
19th Jul 2022, 8:40 AM
Jayakrishna 🇮🇳
+ 2
Yes. Initially it's length is 57 After erase , length is 25 (=>length); after end of loop : 13
19th Jul 2022, 12:30 PM
Jayakrishna 🇮🇳
+ 1
Yes. Check both values initially it's 25 after it is 13
19th Jul 2022, 8:27 AM
Jayakrishna 🇮🇳
+ 1
Yes.
19th Jul 2022, 3:11 PM
Jayakrishna 🇮🇳
- 1
Hi
21st Jul 2022, 6:25 AM
Aravind Vayalapalli
Aravind Vayalapalli - avatar
- 1
Hello
21st Jul 2022, 6:25 AM
Aravind Vayalapalli
Aravind Vayalapalli - avatar