Code:
#include <iostream>
#include <fstream>
using namespace std;
bool addRec(DBRec *pRec) {
// open an output stream
// in binary mode
// and initialize it with the file pointer ready to append
ofstream fout("your.db", ios_base::out | ios_base::binary | ios_base::app);
if (!fout.is_open()) {
fout.write((const char*)pRec, sizeof(DBRec));
fout.close();
return true;
}
return false;
}
Also note that you should not use getline() for binary files (but come to think of it, you might be writing records in text mode, in which case ignore the binary part of my example).
[edit]
You might want to look up the following functions:
Code:
seekg();// move the file pointer
tellg();// returns the current index of the file pointer
seekp();// move the file pointer
tellp();// returns the current index of the file pointer
/* ...g() = input stream, ...p() = output stream */
[/edit]