我一直在使用下面的代码从文本文件中读取两个不同的矩阵。该代码反复重新声明(至少,我认为它重新声明了)局部变量stringvalues
和iss
. 我刚刚意识到变量被重新声明了——我当然不打算重新声明它们。
问题:反复重新声明这些变量有什么影响?
仅供参考:我正在使用 GCC 4.4.3 进行编译。
fstream PW3_in("./input/PW.txt", ios::in);
for(int i=0; i<900; i++)
{
PW3_in.getline(line, 450);
string stringvalues;
stringvalues = line;
istringstream iss (stringvalues,istringstream::in);
iss >> word1 >> word2 >> word3 >> word4 >> word5 >> word6 >> word7 >> word8 >> word9;
num1 = strtod(word1, NULL);
num2 = strtod(word2, NULL);
num3 = strtod(word3, NULL);
num4 = strtod(word4, NULL);
num5 = strtod(word5, NULL);
num6 = strtod(word6, NULL);
num7 = strtod(word7, NULL);
num8 = strtod(word8, NULL);
num9 = strtod(word9, NULL);
PW3[0+i*9]=num1;
PW3[1+i*9]=num2;
PW3[2+i*9]=num3;
PW3[3+i*9]=num4;
PW3[4+i*9]=num5;
PW3[5+i*9]=num6;
PW3[6+i*9]=num7;
PW3[7+i*9]=num8;
PW3[8+i*9]=num9;
}
PW3_in.close();
fstream PP3_in("./input/PP.txt", ios::in);
for(int i=0; i<900; i++)
{
PP3_in.getline(line, 450);
string stringvalues;
stringvalues = line;
istringstream iss (stringvalues,istringstream::in);
iss >> word1 >> word2 >> word3 >> word4 >> word5 >> word6 >> word7 >> word8 >> word9;
num1 = strtod(word1, NULL);
num2 = strtod(word2, NULL);
num3 = strtod(word3, NULL);
num4 = strtod(word4, NULL);
num5 = strtod(word5, NULL);
num6 = strtod(word6, NULL);
num7 = strtod(word7, NULL);
num8 = strtod(word8, NULL);
num9 = strtod(word9, NULL);
PP3[0+i*9]=num1;
PP3[1+i*9]=num2;
PP3[2+i*9]=num3;
PP3[3+i*9]=num4;
PP3[4+i*9]=num5;
PP3[5+i*9]=num6;
PP3[6+i*9]=num7;
PP3[7+i*9]=num8;
PP3[8+i*9]=num9;
}
PP3_in.close();