well, typically, you would read the entire file into some data structure instead of simply searching the file directly. then you'd perform things such as searching, updating, deleting, etc from that DS, and at some point overwriting the file with up-to-date data. to simplify things just place each piece of information on a single line. you'll need to define a class to hold each record and it would be a good idea to overload ifstream/ofstream operators for the class too, ie:
Code:
struct customer {
string name;
friend ifstream & operator >> (ifstream & stream, customer & the) {
return stream >> the.name;
}
};
bool get_customers(const char * file, vector <customer> & array) {
customer record;
ifstream in(file);
array.resize(0);
if(!in) {
return false;
}
while(in.good()) {
if(in >> record) {
array.push_back(record);
}
}
return true;
}
as far as searching for a piece of data a simple loop would suffice.