C++ 错误:向量下标超出范围。第1201行
我面对的是向量下标超出范围的错误。我已经设法找到了导致问题的代码,但我不知道如何解决它 定义的变量类型为C++ 错误:向量下标超出范围。第1201行,c++,visual-c++,vector,decision-tree,outofrangeexception,C++,Visual C++,Vector,Decision Tree,Outofrangeexception,我面对的是向量下标超出范围的错误。我已经设法找到了导致问题的代码,但我不知道如何解决它 定义的变量类型为 typedef vector <string> v1; //vector string typedef vector <v1> v2; // vector (v1) to create a double vector typedef map<string, int> mapstint; //vector (string, int) typedef v
typedef vector <string> v1; //vector string
typedef vector <v1> v2; // vector (v1) to create a double vector
typedef map<string, int> mapstint; //vector (string, int)
typedef vector<int> vint; // vector (int)
typedef vector<double> vd;
typedef向量v1//向量串
typedef向量v2;//vector(v1)创建双向量
typedef映射//向量(字符串,int)
typedef向量vint;//向量(int)
typedef向量vd;
代码如下:
string splitgain(v2 &table)
{
int col, i;
string coln;
mapstint map;
double min = DBL_MAX;
int splitcol = 0;
vint eval,nos;
for (col = 0; col < table[0].size() - 1; col++)
{
coln = table[0][col];
vint counts = countno(table, col);
vd atteval;
double colval = 0.0;
for (i = 1; i < table.size() - 1; i++)
{
double val = 0.0;
if (map.find(table[i][col]) != map.end())
{
map[table[i][col]]++;
}
else
{ map[table[i][col]] = 1;
v2 tempt = prune(table, coln, table[i][col]);
vint ccounts = countno(tempt, tempt[0].size() - 1);
int j, k;
for (j = 0; j < ccounts.size(); j++)
{
double temp = (double)ccounts[j];
val -= (temp / ccounts[ccounts.size() - 1])*(log(temp / ccounts[ccounts.size() - 1]) / log(2));
}
atteval.push_back(val);
val = 0.0;
}
}
//------THIS IS WHERE THE ERROR IS COMING FROM-------
for (i = 0; i < counts.size() - 1; i++)
{
colval += ((double) counts[i] * (double) atteval[i]);
}
//----------------------------------------------------
colval = colval / ((double)counts[counts.size() - 1]);
if (colval <= min)
{
min = colval;
splitcol = col;
}
}
return table[0][splitcol];
}
字符串拆分增益(v2和表格)
{
int col,i;
科恩;
地图地图;
双最小值=DBL_最大值;
int splitcol=0;
葡萄酒评估,编号;
对于(col=0;col<表[0]。size()-1;col++)
{
coln=表[0][col];
葡萄酒计数=计数号(表,列);
vd模式;
双colval=0.0;
对于(i=1;i 如果(colval请注意编译器的警告(或提高警告级别)
所有循环
对于(col=0;col<表[0]。size()-1;col++)
对于(i=1;i
对于(i=0;i
这些都是麻烦
注std::size\u t(0)-1==std::numeric\u limits::max()您不认为countno()
与此相关吗?此外,atteval
来自于其中??well countno()当我运行它时通过了..当我到达那行代码时,它开始显示错误。@WhozCraig..oops ma bad..是的,我看到了..atteval被放在for循环中..解决了..如果我在运行过程中遇到任何其他错误,请告诉我c。非常感谢,伙计..第一件事。我如何提高警告级别。第二,我不明白,怎么办我可以用你贴的便条吗?我对这件事有点陌生。