ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
cout << "enter the title of a book you wish to search for: \n";
cin >> titlesearch;
while (! inBookFile.eof())
if (titlesearch == title)
cout << "Title :\t\t" << title << endl;
cout << "Author :\t\t" << author << endl;
cout << "Publish Date :\t" << date << endl;
cout << "Description :\t" << desc << endl;
else cout << "Unable to open file";
BTW. this is a book keeping program. the file it is looking at follows, ordered as title, author, date, description (ignore the garbled nonsense as i was testing the program out)
red, john, a, a.
red, chris, a, a.
red, turn, a, a.
red, clown, s, s.
blue, john, 3, 3.
df, d, d, d.
john, red, blue, green.
There's a couple of problems with the code you posted concerning Book::search().
First, the following line:
Note the 'i'. If you want to avoid this mistake in the future, just declare an fstream (don't specify 'o' or 'i').
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: