Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old Nov 19, 2012, 03:38 PM   #1
stevegreen22
macrumors newbie
 
Join Date: Aug 2012
Please Help: EXC_BAD_ACCESS error

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.

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
stevegreen22 is offline   0 Reply With Quote

 
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 03:20 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC