Diego Salgado - 2018-04-21

hi, i have a problem, im starting to use files on c++, and i want to make a program that you give an id, and it first search for it on the file, if it isnt found then you can create a new id and add data to it, the thing is that i think its never saving because the output file is always 0kb

#include <iostream>
#include <fstream>

using namespace std;

struct stPeople{
    int id;
    char name[15];
};

int main(){
    stPeople people={0, ""};
    fstream file;
    file.open("data.txt",ios::in|ios::app|ios::binary);
    if(!file){
        cerr<<"Error, no file"<<endl;
        return 1;
    }
    cout<<"Give me the id: ";
    int newID;
    cin>>newID;
    bool existID=false;
    while(!file.eof()){
        file.read(reinterpret_cast<char *>(&people),sizeof(stPeople));
        if(people.id==newID){
            cerr<<"Error, this id is already used"<<endl;
            existID=true;
            break;
        }
    }
    if(existID==false){
        people.id=newID;
        cout<<"Give me the name: ";
        fflush(stdin);
        cin.getline(people.name,15);
        file.write(reinterpret_cast<char *>(&people),sizeof(stPeople));
    }
    file.close();
}