C++ 如何从方法的每个部分的变量中获得相同的数据?
我面临着这样的困境:使用下面类似的代码:C++ 如何从方法的每个部分的变量中获得相同的数据?,c++,arrays,qt,C++,Arrays,Qt,我面临着这样的困境:使用下面类似的代码: //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;
//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
}
//floatArray[totalKeyPoints]在该循环外部声明
对于(int d=0;d //std::cout我猜您希望您的“A”调试输出实际上是:
qDebug() << "A:" << floatArray[gl].response << floatArray[gl].angle << \
floatArray[gl].size << floatArray[gl].class_id;
qDebug()你想要什么还不太清楚。特别是因为问题的标题似乎与其内容无关。temp
,tmp
,temp1
,tmp=temp1[3]
…多么复杂的代码。你应该先尝试简化它,也许你会发现为什么它没有预期的输出。过一会儿你将编辑标题。嗯……我会考虑稍后再重写它,我们很快就需要这段代码:PI不想先相信它,但这是一个复制粘贴错误,但我认为这是错误的s与事实很接近。如果将B输出偏移32行,则第一列将对齐。我也将使用上面的注释,清理代码。但请对此进行upvote。感谢您的建议,进行了一些清理,它现在可以更好地工作:))