I am looking to input individual inputs of a .txt file into my array where each input is separated by a space.
(我希望将.txt文件的各个输入输入到我的数组中,其中每个输入都用空格分隔。)
Then cout these inputs. (然后找出这些输入。)
How do I input multiple values from the .txt file into my array? (如何将.txt文件中的多个值输入到数组中?)
int main()
{
float tempTable[10];
ifstream input;
input.open("temperature.txt");
for (int i = 0; i < 10; i++)
{
input >> tempTable[i];
cout << tempTable[i];
}
input.close();
return 0;
}
With what I have written here I would expect an input of the file to go according to plan with each value entering tempTable[i] however when run the program out puts extreme numbers, ie -1.3e9.
(用我在这里写的内容,我希望文件的输入能够按计划进行,每个值都输入tempTable [i],但是在运行程序时,输入的数字为极值,即-1.3e9。)
The temperature.txt file is as follows:
(temperature.txt文件如下:)
25 20 11.2 30 12.5 3.5 10 13
ask by Rawley Fowler translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…