The code is simplified as follows:
#include <iostream>
#include <string>
using namespace Std;
int main ()
{
String str= "Hello world!";
int len = Str.length ();//Get length
for (int i=0;str[i]!= ' && (I<len); ++i);//Iterate through every variable in a string knowing that a space is found is always an error when debugging in this row because array access is out of bounds
......
}
The red line does go out of bounds because the str[i]!= ', which is executed first, is bound to be out of bounds every time the criteria for a for-in decision is executed.
You can change the order for (int i=0; (i<len) &&str[i]!= "; ++i) if you want not to cross the border.
Did not expect such a small problem, tangled for half an hour, so write down, deepen the impression, in order to develop good code habits.
A hidden array of access to the problem (unexpectedly tangled half an hour, it may be my level is too low)