So, I am trying to run a function that would search a file that is filled with data in this format:
// each line is a library item.
type unique-id title | author-or-artist-name
BOOK 43045 Computer Science Hits | Neil Dale and John Lewis
BOOK 47341 How Computers Work | Ron White
REF 48462 Encyclopedia Britannica | Britannica Inc.
REF 47344 National Geographic Computer | Lucy Spelman
BOOK 48450 Java: A Beginner's Guide | Herbert Schildt
CD 48452 Traveller | Chris Staphleton
CD 48453 How Can It Be Java | Lauren Daigle
REF 48460 The Merriam-Webster Dictionary | Merriam
BOOK 45552 Python Programming | John Zelle
CD 45553 I Still Do Programming | Eric Clapton
BOOK 45557 Beginning Software Engineering | Rod Stephens
REF 45559 A dictionary of nutrition | David Bender
CD 45561 Best Eagles Dictionary Songs | Eagles
CD 46555 The Ultimate Computer Hits | Garth Brooks
The function would check for a specific type of item (listed in the first column) and display the information of all items with that type. So my question is:
Is the best method of listing one type of item from a .txt to search the file for that word, then put all those into a vector and display to user? If not, how should I do this?
Is the best method of listing one type of item from a .txt to search the file for that word
It would work but unlikely to be seen as very practical for a real-life/professional solution.
then put all those into a vector and display to user?
You might need to split the lines into more than two columns but it would be a good way to go, <maps> too might be worth a look because they are accessible using key values so are quicker to access.
I would create a struct Media, read the file line by line into the struct and store it in a vector. Then you can easily use the find, sort algorithms of the stl.
1 2 3 4 5 6 7
struct Media
{
string type;
int id;
string title;
string author;
}