如何从方法的每个部分的变量中获得相同的数据
How can I get the same data from a variable in every part of the method?
我遇到了这样的困境:使用下面的类似代码:
//floatArray[totalKeyPoints] declared just outside this loop
for(int d = 0; d < totalGroups; d++)
{
std::string STRING = "";
QString lk = "test" + QString::number(d) + ".txt";
std::string kl;
kl = lk.toStdString();
std::ifstream infile(kl.c_str());
//std::cout << "FILEPATH: " << kl.c_str() << std::endl;
int gl = 0;
while(endFile != true)
{
endFile = infile.eof();
getline(infile,STRING);
if(STRING.empty() == false && endFile == false && gl < totalKeyPoints)
{
QString temp = STRING.c_str();
QStringList temp1 = temp.split(" ");
QString tmp = temp1[0];
floatArray[gl].response = tmp.toFloat();
tmp = temp1[1];
floatArray[gl].angle = tmp.toFloat();
tmp = temp1[2];
floatArray[gl].size = tmp.toFloat();
tmp = temp1[3];
floatArray[gl].class_id = tmp.toInt();
if(firstRun2 == true)
qDebug() << "A:"
<< floatArray[gl].response
<< floatArray[gl].angle
<< floatArray[gl].size
<< floatArray[gl].class_id; //TAKE NOTE
int xs = tmp.toInt();
kpPerGroup[xs]++;
gl++;
}
}
infile.close();
if(d < totalGroups)
{
endFile = false;
}
}
for (int d = 0; d < totalKeyPoints; d++)
{
if(firstRun2 == true)
qDebug() << "B:"
<< floatArray[d].response
<< floatArray[d].angle
<< floatArray[d].size << floatArray[d].class_id; //TAKE NOTE
}
我已经在这个粘贴框中记录了两个qDebug
命令的输出:使用A和B
为什么我会有这种行为?有没有一种方法可以让我在整个代码中只有SET a值?
我猜您希望您的"A"调试输出实际为:
qDebug() << "A:" << floatArray[gl].response << floatArray[gl].angle <<
floatArray[gl].size << floatArray[gl].class_id;
对所有索引使用CCD_ 2而不是对最后三个使用d
。在第一个循环中,索引CCD_ 4似乎与CCD_ 5无关。往好了说会得到不正确的输出,往坏了说会出现数组溢出/崩溃。
相关文章:
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 我可以在 C++ 中将数据成员/变量从其定义之外添加到结构中吗?
- 从模板创建通用打印函数,以打印基元数据类型变量的值
- 如何在变量中插入多种不同长度的数据类型?
- 如果变量数据包含大于 vector 所有元素的整数,则仅在视觉工作室上接收"矢量下标超出范围"?
- 逐行读取文件,并将数据插入变量和数组中
- 如何使用C++中可以具有多种数据类型的单个变量
- C++ 成员不是变量,而只是数据类型的名称吗?
- 指针数据类型变量如何包含对象?
- 将数据从 SQLite 数据库保存到变量中
- 如何从excel文件中读取数据并存储到变量中?
- 如果一个变量在它之前释放了另一个(相同的数据类型)变量,如何将其分配给内存?
- 如何有效地实现将向量的数据分配给多个变量?
- 返回实例变量的c++方法可以访问变量中的数据,但不能更改它,但在编译时不会生成错误
- C++ Eclipse:二叉搜索树节点>数据=变量似乎不起作用
- C++运算符重载和访问私有数据变量
- 如何从输入文件C++的行读取多个数据变量
- "数据变量"是什么意思?
- 区分指针和数据变量
- 将文件数据变量存储在维度数组中