Reputation: 1863
I am trying to append data into a file, and I am having trouble in checking if the input data is already there in the file. If the data is already there in the file, then it won't add that data again. Can anyone tell me what shall I do in this case? I have attached a copy of my code for your reference. Thanks!
void addentry(char* name, char* entry){
ifstream in_file(name);
ofstream out_file(name, ios::app);
out_file << entry << endl;
if(!in_file) {
cout << "This is the first entry of this person" << endl;
}
int_file.close();
out_file.close();
}
Upvotes: 3
Views: 182
Reputation: 416
To retrieve the data you must know how you inserted it . instead of writing in text file write in .ini
file it will be really fast for your kind of operation .
when you write in .ini
file a single loop will do this stuff for you . to read about ini file i am attaching the links hope that will help you.
http://en.wikipedia.org/wiki/INI_file#Accessing_INI_files
http://sdl-cfg.sourceforge.net/
http://sourceforge.net/projects/libini/
http://www.codeproject.com/KB/files/config-file-parser.aspx
Upvotes: 1
Reputation: 590
read file data and count character till EOF (End of file). Check if count is not equal to zero. If it is so append else don't. You have not provided whole code otherwise I would have compiled and then send you code as well.
Upvotes: 2