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

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: EXC_BAD_ACCESS problem larswik iPhone/iPad Programming 0 Jan 27, 2014 08:33 PM
Best easy way to debug EXC_BAD_ACCESS code 1 moonman239 iPhone/iPad Programming 25 Nov 6, 2013 11:18 PM
EXC_BAD_ACCESS - Trying to retrieve string from NSArray moonman239 iPhone/iPad Programming 12 Sep 9, 2013 07:06 AM
Objective-C noob: EXC_BAD_ACCESS with simple print method? dancks Mac Programming 14 Apr 27, 2013 04:47 PM
Getting crazy also with EXC_BAD_ACCESS jivaro Mac Programming 5 Jun 1, 2012 08:49 PM

Forum Jump

All times are GMT -5. The time now is 02:15 AM.

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

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