reading calm record until eof repeats final line
the following c++ formula uses ifstream vigilant review integers calm record (which array per line) until hits eof. since does review integer final line twice? repair this?
code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream ifile("input.txt"); // input.txt integers, per line
while (!ifile.eof())
{
int x;
ifile >> x;
cerr << x << endl;
}
relapse 0;
}
input.txt:
10
20
30
output:
10
20
30
30
note: i've skipped blunder checking formula keep formula dash small. above intrepidity seen windows (visual c++), cygwin (gcc) linux (gcc).
Comments
Post a Comment