Lines From File To Structs? Help Plz

I'm trying to make a song library/search sort of program. The program needs to have an entry/ID number for each song (Going up by one for each new song added to the library) I have a text file with a listing of songs like the following:

song.txt
1
2
3
4
5
6
7
8
9
Song=1
Name=Objects of Desire
Artist=NinjaParty
Date_Added=2012-08-16

Song=2
Name=Code Monkey
Artist=Jonathan Coulton
Date_Added=2013-08-07


I've correctly set up a struct for each song entry and a music library to hold all of the information for each song.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct MusicEntry
{
string name;
string artist;
string date_added;

MusicEntry() : name(""), artist(""),date_added("") {};
MusicEntry(string n, string a, string d) : name(n), artist(a), size(s), date_added(d) {};

string to_string();
};

struct MusicLibrary
{
MusicLibrary(string);
};


I've also set up a function that correctly reads the text file.

1
2
3
4
5
6
7
8
9
10
11
12
MusicLibrary::MusicLibrary(string f)
{
ifstream song_file;
song_file.open(f);

while(!song_file.eof())
{
string line;
getline(song_file, line);
istringstream iss(line);
cout << line << endl;
}


My question(s) however, is how do I get it to add each song from the text file to it's own MusicEntry? How does it know that one of the songs in the file is "over", can you set the program to detect a blank line?

Would you also recommend that I use 2 maps for this project? One map storing the Entry # and the MusicEntry and another map inside each MusicEntry that contains (Name, Jonthan Coutlon), etc for all the components of each song?

Thanks in advance for any hints/help guys!
Last edited on
Well, you could use a delimiter between each entry to note where the song information ends between two. Not sure whether a blank line would be ideal... You could see whether there is some other character to be put into it.
And how would you "place" the information from each line to the correct spot in a new MusicEntry? Would you need to split a line into words and add them into a vector and then do first,second,third that correspond to the element of the song (Title, Artist, etc.)? But in that case, what if the Artist is missing/not given in the file?

Something tells me I might also be over thinking this., I tend to do that a lot :\
Bump
Topic archived. No new replies allowed.