I am runnig a program that loops ~100,000 times. but it is going through this for loop once and then is returning
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check
It compiles fine.
lines comented out were previous problem sections
Well the problem is pretty clear. You're accessing outside of the bounds of your vector.
This raises a huge red flag for me:
for (int i=1;i<=ph_n; i++)
I don't know what ph_n is, but if it's the size of your vector, this is wrong.
Remember that indexes always start at zero, not at 1. So if your array has 5 elements... then element #5 is out of bounds (only elements 0 - 4 are valid).
Typical for loops look like so: for (int i=0;i<ph_n; i++)
Note how I start at zero and do < ph_n instead of <= ph_n