私は非常に単純なコードを持っていますが、間違いを見つけることができません。タスク: float/double 値を含むテキスト ファイルを読みたいです。テキスト ファイルは次のようになります。
--datalog.txt--
3.000315
3.000944
3.001572
3.002199
3.002829
3.003457
3.004085
3.004714
3.005342
3.005970
3.006599
3.007227
3.007855
3.008483
3.009112
3.009740
3.010368
3.010997
コードは次のようになります
--dummy_c++.cpp--
#include <iostream>
#include <fstream>
#include <stdlib.h> //for exit()function
using namespace std;
int main()
{
ifstream infile;
double val;
infile.open("datalog");
for (int i=0; i<=20; i++)
{
if(infile >> val){
cout << val << endl;
} else {
cout << "end of file" << endl;
}
}
return 0;
}
出力は次のようになります。
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
end of file
期待どおり、datalog.txt ファイルと同じように出力されます。
間違いを見つけるのを手伝ってもらえますか?
ありがとう、ミリンド。