airport air(1,2,3); //an airport constructor ofstream myfile; myfile.open(\"rishab\",ios::app||ios::binary); myfile.write((char*)air,sizeof(airport); myfile.close();
You can program it like this.
struct AirPort { int a; int b; int c; }; int main() { std::vector airportList; FILE* fp = fopen(filename,"rb"); if( NULL != fp) { while(!feof(fp)) { AirPort ap; if (fread(&ap,sizeof(ap),1,fp)==1) { airportList.push_back(ap); } } } fclose(fp); return 0; }