You make Wph too small, I suspect. We do not know what it is mydata.data.size(), but I assume that it is too small.
From the code, it looks like the right size
Wph.resize(mydata.p.size() * mydata.t.size());
However, in C ++ we are trying to write security code, so making such errors is more difficult.
vector<double> Wph;
for (size_t t = 0; t < mydata.t.size(); t++)
{
double t0 = (PI / 180.0) * mydata.t[t];
for (size_t p = 0; p < mydata.p.size(); p++)
{
double _Wph = 5;
Wph.push_back(_Wph);
}
}
If you must pre-select the size, then at least change
Wph[data] = _Wph;
to
Wph.at(data) = _Wph;
at () works just like [], except that at () checks that you haven't passed the end of the array and throw an exception.
source
share