I have a problem regarding the code for searching a text file. My program is able to add information, display, and save it to a text file, but I'm having trouble figuring out how to search the text file for a particular entry.
The entries in my text file look like this:
0843543 Intro to C++ HH117
I'm trying to implement a function to search the text file by the first value (ie: 0843543). I tried using a strcmp but it would not find the match.
The code for this was:
Once it finds the match I need to be able to delete it or change it. Thanks again for all the help.Code:void SearchClass() { char input[7]; char course[7]; int i; cout<<"enter in course to search: "; cin>>course; fstream readfile; readfile.open("C:/WINDOWS/Desktop/class.txt", ios::in); readfile.getline(input, 7); while(!readfile.eof()) { if(strcmp(course, input)==0) {cout<<"match";} else {cout<<"no match";} readfile.getline(input, 7); } readfile.close(); }



LinkBack URL
About LinkBacks



I hope this helps. Also, I don't believe there's any easy way to delete or modify entries in a file; the only way I know of that's foolproof is to delete the file and re-write it with the modifications. 
). If >> and << for the various (i/o)stream's work with std::string's, then yeah by all means don't bother with c_str() and char[].