【发布时间】:2014-02-19 21:16:42
【问题描述】:
我很确定这是一个常见问题,但我找不到与我类似的示例,所以.. 我有一个名为 input.txt 的文本文件,其中包含:0.0001234 1.0005434 0.0005678 1.0023423 0.00063452 1.0001546 0.00074321 1.00017654。 现在我想编写一个程序将其读入数组,然后快速检查它是否有效。到目前为止,我有:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
double PA[8];
int n;
ifstream myfile ("input.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << PA[line]<< endl;
}
myfile.close();
}
else cout << "Unable to open file";
for (n=0; n<8; n++) // to print the array, to check my work
{
cout << " {" << PA[n] << "} ";
}
system("PAUSE");
return 0;
}
到目前为止,我的问题是我不断收到错误:未声明行。我想稍后将数组与浮点数一起使用来计算新数据。我想我做错了。有什么帮助吗?谢谢!
【问题讨论】: