I'm having trouble with file reading/formatting ...
I am given a file songs.txt which contains data on each line in the following format
songtitle__artistlastname, artistfirstname__7characterIDnum__albumname
for example:
A KISS TO BUILD A DREAM ON___ARMSTRONG, LOUIS___MAG6037___BEST LOVED BALLADS CD+G
In my main file I have:
Code:
ifstream filename("songs.txt");
Code:
vector<Song> Info; //vector object info takes in a Song object
Song input; //object created whose information will be parsed
while(filename >> input) //calls overloaded >> operator
//read while data exists to be read
{
Info.push_back(input);//appends the string to the vector
}
and in my songs.cpp file I have overloaded the >> operator like so:
Code:
istream& operator>> (istream &is, Song &song)
{
string lastname;
string firstname;
getline(is, song.title, '_');
is.ignore();
is >> lastname >> ws >> firstname;
is.ignore();
is >> song.album;
song.artist = lastname + firstname;
return is;
}
and I have also overloaded the << operator like so:
Code:
ostream& operator<< (ostream &os, Song &song)
{
os << setw(30) << left << song.title << ':'
<< song.artist << ':'
<< setw(20) << left << song.album;
return os;
}
I want to be able to store the song's title, artist, and album.
Technically I don't need the 7 character ID num but for now I'm just including it as part of the album name.
I just used the ':' so that I know when each variable (title, artist, album) ends
My concern is that I'm not able to store the artist name correctly
For example it turns out like this:
A KISS TO BUILD A DREAM ON:_ARMSTRONG,LOUIS___MAG6037___BEST:LOVED BALLADS CD+G
I want to ignore the dash right after the artists first name so that its not included in song.artist.