错误:矢量下标超出范围.1201路
Error: Vector subscript out of range. Line 1201
我面对的向量下标超出范围 erro。我已经设法找到了导致问题的代码,但我不知道如何解决它。
定义的变量类型为,
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];
}
请注意编译器的警告(或提高警告级别)
所有循环
for (col = 0;col for (i = 1;
i for (i
= 0; i
是麻烦。
注意标准::size_t(0) - 1 == 标准::numeric_limits::max()
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- 尝试通过多个向量访问变量时,向量下标超出范围
- 错误:未在此范围内声明'reverse'
- 数到第n个楼梯的路(顺序无关紧要)
- 正在将指针转换为范围
- 使用std::transform将一个范围的元素添加到另一个范围中
- vscode g++链路故障:体系结构x86_64的未定义符号
- 在基于范围的for循环中使用结构化绑定声明
- 如何计算数据类型的范围,例如int
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 在C++中查找范围的长度
- 如何设置一个范围来提取我想要获得的信息
- 并行用于C++17中数组索引范围内的循环
- 为左值和右值的包装器实现C++范围
- 求出有多少个数字是完美平方,而sqrt()是L,R范围内的素数
- 关于:C++中异常对象的范围:为什么我没有得到副本?
- 超出范围时使用对象
- 错误:矢量下标超出范围.1201路
- 矢量下标超出范围.1140路.C++
- C++矢量下标超出范围行1201