当读入第4个数字后,文件就已经到达末尾了,while循环就不成立了。
while (filein.good())
{
cout << getcont << ' ';
filein >> getcont;
}
最简单的方法就是:
//insert the content into the variable
double getcont;
filein >> getcont;
//judge if the file readin is EOF or fail
while (filein.good())
{
cout << getcont << ' ';
filein >> getcont;
}
直接改为:
double getcont;
while (filein>> getcont)
{
cout << getcont << ' ';
}