C++, getline, searching through file issue
Hello World!!!
ok I am taking a my first C++ class and we are suppose to write a very simple program. I have worked my way up to writing to a file, listing the contents of the file, and now i am on to the fun part of searching through the file for a particular word/string. the program i have made compiles nicely, however, the search function does not provide me with the information i want it to. I am going to give the portion of code that is giving me the problem. Any help would be appreciated. Code:
void Book::search() Code:
red, john, a, a. |
P.S. i dont know if i was correct using the stringstream stream() function. but it worked previously for listing all of the books in the file. as shown below
Code:
void Book::display() |
There's a couple of problems with the code you posted concerning Book::search().
First, the following line: Code:
ofstream inBookFile("book.txt",ios::in); Code:
ifstream inBookFile("book.txt",ios::in); The next problem is quite simple; you are not reading from the file! I personally do not like checking for eof() because the eof-flag is not set until a read fails. Thus I recommend that you consider setting up your while loop as follows: Code:
... |
All times are GMT -5. The time now is 03:31 PM. |