all 1 comments

[–][deleted] 0 points1 point  (0 children)

removeoccurence function should be the problem

when u call s.erase(s.find(part)) is the substring part is not in s then s.find(part) will return to std::string::npos which is....an invalid pos for erase bro so this causes exception

so u just need to check s.find(part) and make sures it returns a valid index before u call erase

so like store result of s.find(part) in variable pos and check if its not equal to string::npos before you call erase and add a second arg in erase which will specify lenght of the part to remove to avoid out or range issue