Hi all,
I'm new to C++ and have come across this error when running part of the program.
I'm overloading the >> operator, reading in a file and creating a list of album objects and adding relevant tracks to the albums.
The task itself works fine, in that the albums are created with tracks and so on but to get it to work I needed ot use a pointer which seems to tbe the cause of this issue but I don't know enough to solve. I've spent a while unting around online adn have tried using auto ptr and unique ptr but both give me other errors which, yet again I don't know how to navigate.
Could some shed some light please?
many thanks!
code:
--excuse comments.
I'm new to C++ and have come across this error when running part of the program.
I'm overloading the >> operator, reading in a file and creating a list of album objects and adding relevant tracks to the albums.
The task itself works fine, in that the albums are created with tracks and so on but to get it to work I needed ot use a pointer which seems to tbe the cause of this issue but I don't know enough to solve. I've spent a while unting around online adn have tried using auto ptr and unique ptr but both give me other errors which, yet again I don't know how to navigate.
Could some shed some light please?
many thanks!
code:
--excuse comments.
Code:
inline istream& operator>>(istream& is, AlbumCollection& albums){
std::string artistName, albumName, trackName, duration;
std::string firstline;
//std::auto_ptr<Album> Album_memory_manager(new Album);
//Album tempAlbum;
Album tempAlbumWithTracks;
vector<Album>albumVector;
vector<Track>trackVector;
//Duration duration;
//*Album_memory_manager = TESTTTTT;
Album* TESTTTTT;
std::auto_ptr<Album> Album_memory_manager(new Album);
//make stream from first line
stringstream stringstream1(firstline);
//loop through while there is still a line
while (getline(is, firstline)){
//IF THIS LINE IS NOT A TRACK IT MUST BE AN ALBUM
if (!(firstline[8] == '-')){
stringstream stringstreamTeast(firstline);
//NEED TO MAKE A NEW ALBUM AND EXTRACT TITLE & ARTIST
if(getline(stringstreamTeast, artistName, ':')){
artistName = artistName;
//cout << "\nArtist:: " << artistName << endl;
//YES!!!!
if(getline(stringstreamTeast, albumName, '\n')){
albumName = albumName;
cout << endl;//"Album:: " << albumName << endl;
}
if (TESTTTTT != 0){
albumVector.push_back(*TESTTTTT);
}
TESTTTTT = new Album(artistName, albumName);
}
}
else if (firstline[8] == '-') { //Not a new album //could use [3] etc
//stream for track
stringstream meh(firstline);
if(getline(meh, albumName, '-')){ //ERROR HERE
duration = firstline.substr(0,7);
trackName = firstline.substr(10, firstline.size());
Duration d;
stringstream trackConversion(duration);
trackConversion >> d;
//create new track
Track testTrack(trackName, d);
// cout << "TEST OUTPUT OF TRACKS " << testTrack<<endl;
TESTTTTT->addTrack(testTrack);
trackVector.push_back(testTrack);
}
}//end else if
}
//add final album to vector
albumVector.push_back(*TESTTTTT);
//delete TESTTTTT;
//FOR ****S SAKE!!!
//delete TESTTTTT;
//finally create the collection
// albums = AlbumCollection(albumVector);
//proves tracks are being added ok!
// for (vector<Track>::iterator iter = trackVector.begin(); iter !=trackVector.end(); iter++){
//
// cout <<"Iteator test for tracks"<< *iter << endl;
// }
//proves albums are being added ok
for (vector<Album>::iterator iter = albumVector.begin(); iter !=albumVector.end(); iter++){
cout <<"Iteator test for albums\n"<< *iter << endl;
}
return is;
}//end function