getlinefin FileLine getlinefin FileLine if found iffinname

Getlinefin fileline getlinefin fileline if found

This preview shows page 17 - 28 out of 28 pages.

getline(fin, FileLine); getline(fin, FileLine); } if (!found) { foutcopy<<FileLine<<endl; } } /*if(fin==name) { cout<<name; }*/ fin.close(); foutcopy.close(); remove( "out.txt" ); rename( "outcopy.txt" , "out.txt" ); cout<< "\n\n Data deleted" ; } void editbooks() { ifstream fin; fin.open( "out.txt" ); ofstream foutcopy; foutcopy.open( "outcopy.txt" ); string bokTitle, FileLine; cin.ignore(); Books bk; cout<< "Enter Title of the book" <<endl; getline(cin,bokTitle); while (getline(fin, FileLine))
Image of page 17
{ if (FileLine.find(bokTitle,0) != string::npos) { cout<<endl; cout<<FileLine<<endl; foutcopy<<FileLine<<endl; getline(fin, FileLine); foutcopy<<FileLine<<endl; cout<< "Enter books author : " ; //<<endl; getline(cin, bk.BookAuthor); foutcopy<< "Author: \t" <<bk.BookAuthor<<endl; cout<< "Enter Books publisher : " ; //<<endl; getline(cin,bk.BookPublisher); foutcopy<< "Publisher:\t" <<bk.BookPublisher<<endl; cout<< "Enter books edition : " ; //<<endl; getline(cin,bk.BookEdition); foutcopy<< "Edition :\t" <<bk.BookEdition<<endl; cout<< "Enter No. of copies : " ; //<<endl; cin>>bk.BookCopies; foutcopy<< "No. of copies:\t" <<bk.BookCopies<<endl; foutcopy<< "Available copies:\t" <<bk.BookCopies<<endl; cout<< "Enter cost : " ; //<<endl; cin>>bk.BookCost; foutcopy<< "Cost:\t\t" <<bk.BookCost<<endl; //cout<<FileLine<<endl; getline(fin, FileLine); getline(fin, FileLine);
Image of page 18
//cout<<FileLine<<endl; getline(fin, FileLine); //cout<<FileLine<<endl; getline(fin, FileLine); //cout<<FileLine<<endl; getline(fin, FileLine); //cout<<FileLine<<endl; /*getline(fin, FileLine); cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl;*/ getline(fin, FileLine); getline(fin, FileLine); } foutcopy<<FileLine<<endl; } /*if(fin==name) { cout<<name; }*/ fin.close(); foutcopy.close(); remove( "out.txt" ); rename( "outcopy.txt" , "out.txt" ); cout<< "\n\n Record Updated Successfully." ; }
Image of page 19
void searchbooks() { int option; cout<< "Please select option from the following :" <<endl<< "1.Veiw all books" <<endl<< "2.Search books" <<endl<< "3.View All Issued Books" <<endl<< "4.View All returned books" <<endl; cin>>option; if (option==1) { veiwbooks(); } else if (option==2) { ifstream fin; fin.open( "out.txt" ); string name, FileLine; cin.ignore(); Books bk; cout<< "Enter Title of the book" <<endl; getline(cin,name); while (getline(fin, FileLine)) { if (FileLine.find(name,0) != string::npos) { cout<<endl; cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl; getline(fin, FileLine);
Image of page 20
cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl; getline(fin, FileLine); cout<<FileLine<<endl; } } fin.close(); } else if (option == 3) { viewIssuedbooks(); } else if (option == 4) { viewreturnbooks(); } else { cout<< "Invalid Selection" <<endl; } return ;
Image of page 21
} void veiwbooks() { cout<<endl<<endl<<endl; string show; ifstream fin; fin.open( "out.txt" ); while (getline(fin,show)) { cout<<show<<endl; } fin.close(); return ; } void viewIssuedbooks() { cout<<endl<<endl<<endl; string show; ifstream fin; fin.open( "issue.txt" ); while (getline(fin,show)) { cout<<show<<endl; } fin.close(); return ; } void viewreturnbooks()
Image of page 22
{ cout<<endl<<endl<<endl; string show; ifstream fin; fin.open( "return.txt" ); while (getline(fin,show)) { cout<<show<<endl; } fin.close(); return ; } OUTPUT:
Image of page 23
Image of page 24
Image of page 25
Image of page 26
Image of page 27
Image of page 28

You've reached the end of your free preview.

Want to read all 28 pages?

  • Spring '17
  • aaron
  • Return statement, getline, Void type, ofstream foutcopy

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes