Can someone please help me with this coding? After I press debug it executes the program but then an error message pops stating "string subscript out of range." I've tried everything i could think of but still got no solution.
while (i < str.length())
{
str[i] = str[i + 1];
i++;
}
if I have a string "Foobar", what is its length, as returned by string::length()? 6. So if i=5, i < length() right? So in that case, you are setting:
str[5] = str[6]. Is str[6] a valid subscript?
i tried various different ways according to your explanation but i still cant manage to get it correctly. Can you please just tell me exactly what to change?
i dont know which number will be a valid subscript bcuz i dont know exactly what to change to check it. the program is suppose to take a word for, example "there" and remove the vowels so it becomes "thr".. i understand exactly what you want me to do but i just dont know where to make the changes
C++ strings begin at subscript '0', so in string strCat = "cat"; strCat[0] is 'c', strCat[1] is 'a', etc. The length of the string is 3, but the last valid subscript is strCat[2]. What does strCat[3] give you? This is somewhat undefined. So what happens when you do str[5] = str[6] on a string with length 6? Try to amend your logic so you stay within the bounds of the subscript.
i dont understand what you mean by str[5] = str[6]. Your trying to say what happens when you change from 5 to 6? I tried str[5] = str[i+1] and it still gave me the same error even when i changed the 5 to 6 and i used a string with 5, 6, or 7 letters in a word. I understand what you mean by a valid subscript because in the word "there" str[4] would be the last valid subscript but again i dont know exactly where to make the changes to see what happens when i do str[5] = str[6] on a string with length 6.