ofstream and ifstream for searching and writing
I have a question to ask regarding reading/writing simultaneously to random files. I've searched the FAQ and the forums from DAY 1 and I have not come accross anything like what I'm trying to do. Maybe I'm just weird. I dunno. But I realise I need your help.
Here's the deal: I'm trying to read and write simultaneously to the same file using ifstream (read) and ofstream variables. The thing is, these two are separate functions. When I search for a record with ifstream, the ofstream variable doesn't know where the ifstream variable is. So I have to do a seekp on the ofstream based on the ifstream's tellg. Get it?
In short, everytime I search using ifstream, I have to update ofstream on where ifstream is so that I can write to that position. The problem is that it doesn't always work.
I miss the days of C when I could just use ONE FILE *fptr variable to do both.
My question is, am I doing something wrong here? Is that the way it's supposed to be done in C++? Your comments please.