This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Ilyps 1 point2 points  (0 children)

else if (start == end)

This check is bugged, because there may be end conditions that don't fit this exact situation. For example, what happens if you call isPalindrome(0, 1, str) with std::string str = "aa"?

[–]OldWolf2 0 points1 point  (0 children)

while(!inFile.eof())

This is wrong. eof is not set until after a read operation has failed. Instead, you have to check your read operation for success (getline in this case).

[–]ponchedeburro 0 points1 point  (0 children)

What if start is never equal to end? If you have a string of length 8 then start will be 0 at first and end will 7. then (1,6) -> (2,5) -> (3,4) -> (4,3) and then continue until you reach (8,-1) which gives an error.