Accessing an array out of bounds is undefined behavior. The best thing for it to do would be to immediately crash your program, but it doesn't have to.
If you want to add bounds checking that will throw an exception, the simplest way would be to use a std::vector or std::array and change your data[i] calls to data.at(i).
In the future, include the types of all objects used in the code. If we don't know the types we don't know the semantics, and thus the code is meaningless to us.
It's a out of range problem. My previous compiler showed the runtime error when I did something like in my example. I didnt have to create a vector or an array.
Maybe it's a compiler setting/option that needs to be turned on?
use .at() instead of [] which would alert you? (try catch block)
or handle it yourself... if(string.length() > 2)
else.. something
we tested .at a while back and its performance hit is substantial if you are iterating something of size. For one letter no one will notice.