Saturday, May 22, 2010

C++ question? Can you tell me why this isnt working?

As the title says:





void DisplayNamNum()


{


int test = Vector.size();





for(int i=0;i %26lt;= test; i++)


{


cout%26lt;%26lt; Vector[i].info %26lt;%26lt; "-" %26lt;%26lt; Vector[i].data %26lt;%26lt;endl;


}


MainMenu();


}





any thoughts as to why this gives me a runtime error?

C++ question? Can you tell me why this isnt working?
The array indexes run from 0 to size-1. Testing for i %26lt;= test will cause an out-of-bounds error on the last loop.





Change the test in the for statement to: i %26lt; test.
Reply:Based from the code, I think it would be much better to use Vector.at(i) instead of using Vector[i]. Also, if none of the answers here would help you, please post the WHOLE code.

gladiolus

No comments:

Post a Comment