my file:
1
2
3
Here is my question:
- How does function
is::eof
work? - Why does the last integer repeat when I use
\n
at the end of the file and doesn't if I don't use it? - If I use character instead of integer and don't use
\n
at the end of the file, so why does the last character repeats? my other file:
a
b
c
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream file("D:\\code\\codec++\\hoctap.txt");
if(file.fail()) {
cout << "ERROR";
exit (1);
}
while(!file.eof()) {
int a;
file >> a;
cout << a << " ";
}
file.close();
return 0;
}