[Solved] difference between string size() function and strlen in this particular case


In one case, you use size_t, in the other case you use int.

If the length is for example 6 characters, then s.size () – 7 is not -1, but one huge number and everything goes wrong. But if you write int len = strlen (…), then len – 7 is indeed -1 and everything is fine.

When I see a number subtracted from size_t, that’s an immediate red flag. Write “i + 7 ≤ s.size()”, not “i ≤ s.size() – 7”.

4

solved difference between string size() function and strlen in this particular case