I have a question. Why my program don't read the last integer if I don't put a space at the end of file? If I have a text file with a only number, without end space, the program don't read anything.
This is my program :
#include <iostream>
#include <fstream>
using namespace std;
int main(){
    fstream f1,f2;
    int k;
    int q;
    cout << "Inserisci numero lettere da leggere : ";
    cin >> q;
    f1.open("in.txt", ios::in);
    f2.open("out.txt", ios::out);
    if(f1.fail()){
        cout << "Impossibile aprire il file";
        exit(1);
    }
    f1 >> k;
    while( !f1.eof() && q > 0){
        q--;
        cout << k << '\n';
        f2 << k;
        f1 >> k;
    }
    f1.close();
    f2.close();
    return 0;
}
 
     
    