我對着矢量標超出範圍埃羅的。我設法找到導致問題的代碼,但我不知道如何解決它。錯誤:向量下標超出範圍。 1201線
定義的變量類型,
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;
的代碼如下,
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];
}
你不覺得'countno()'是有關呢?此外,'atteval'形式*其中*? – WhozCraig
井countno()穿過時,我正在運行它..它開始表示錯誤當我達到該代碼行。 – Novjean
@WhozCraig .. oops ma bad .. ya我看到了.. atteval被放置在for循環中..得到了解決.. lemme c,如果我在我的路上遇到任何其他錯誤。多謝隊友.. – Novjean