I’m getting a stack overflow on the first iteration of this for loop
for (int q = 0; q < SIZEN; q++)
{
cout<<nList[q]<<" ";
}
nList is a vector of type int with 376 items. The size of nList depends on a constant defined in the program. The program works for every value up to 376, then after 376 it stops working.
Any thoughts?
If by “stops working”, you mean crashes, then you’re probably reading past the end of the buffer.
vector::operator[]is not range checked, so it will let you shoot yourself in the foot.If you want to traverse a vector, use an iterator, or at the very least
nList.size().So with least modifications to your code:
or with iterators