im gettin this really annoying error message. I know Im only new to this but it seems the type of thing I could figure out. Can anyone show me where im going wrong please?
The message at run time is: Debug Assertion Failed! Program: .... File: c:\program files\microsoft visual studio 10.0\vc\include\vector Line: 932 Expression: Vector subscript out of range
and the code is
#include<iostream>
#include<vector>
using namespace std;
struct Things {
string name;
string color;
string poison;
string burns;
double height;
};
typedef vector<Things> Forest;
void read_data(Forest& v) {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cout << "DINTRE" << endl;
cin >> v[i].name;
cout << v[i].name << endl;
}
}
int count(const Forest& v, string name, string color, string poison, string burns, double height) {
int x = v.size();
int cont = 0;
for (int i = 0; i < x; ++i) {
if (v[i].name == name or name == "*") {
if (v[i].color == color or color == "*") {
if (v[i].poison == poison or poison == "*") {
if (v[i].burns == burns or burns == "*") {
if (v[i].height >= height or height == 0) ++cont;
}
}
}
}
}
return cont;
}
int main() {
Forest v;
read_data(v);
vector<string> pregunta(4);
while (cin >> pregunta[0]) {
for (int i = 1; i < 4; ++i) {
cin >> pregunta[i];
}
double height;
cin >> height;
cout << count(v, pregunta[0], pregunta[1], pregunta[2], pregunta[3], height) << endl;
}
}