What is wrong with this code

for (int i=0; i<= phrase.size(); ++i)
{
cout <<"Character at position"is": <<phrase[i] << endl;
}
cout <<"Character at position"is": <<phrase[i] << endl;

At a rough guess, you meant to write
cout << "Character at position " << i << " is " << phrase[i] << endl;
Last edited on
The size of the container is not a valid index so you need to use < instead of <=.

 
for (int i = 0; i < phrase.size(); ++i)
Last edited on
Topic archived. No new replies allowed.