jeudi 19 mars 2015

C++ overload the stream I/O operators when reading from a txt file


I have a text file full of information about books for a library simulation program, here's a sample:



P.G. Wodehouse, "Heavy Weather" (336 pp.) [PH.409 AVAILABLE FOR LENDING]
Isaac Asimov, "The Gods Themselves" (288 pp.) [UM.824 AVAILABLE FOR LENDING]
Olaf Stapledon, "Odd John" (224 pp.) [LN.171 AVAILABLE FOR LENDING]
...etc


I'm new to C++ and I've written this as a start but as you can see there's no clear separation between each piece of data I need and I can't figure out how to easily separate them, please help:



istream& operator<<(istream& in, LibraryBook& b){
string author,title,classification,status;
int pages;
in >> author >> title >> pages >> classification >> status;
return in;
}



Aucun commentaire:

Enregistrer un commentaire