CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    34

    Music Organizing Program (NEED HELP)

    ....
    Last edited by aurorablaze07; July 30th, 2009 at 09:59 AM.

  2. #2
    Join Date
    Dec 2008
    Posts
    10

    Re: Music Organizing Program (NEED HELP)

    Hi Aurora,

    Since this looks like a school assignment, I won't say exactly seems wrong to me, but I'll give you a hint...at least from a quick observations:

    [code]
    //this should put it in a vector
    bool Catalog::Read(ifstream &file)
    {
    string that_file;
    while(file >> that_file) //should read and store in the vector
    {
    getline(file, that_file);
    Song some_song(some_song.GetTitle(), some_song.GetArtist(), some_song.GetAlbum(), some_song.GetType() ); //take it apart and write the song on to that
    Add(some_song); //this should call Add and add the songs

    }
    return true;
    }
    [/code
    You are using the >> and getline functions in a suspicious way. You might take a look at the documentation for std::istream to see if these two functions really are appropriate for your needs.

    Next, instantiating some_song looks like a prime opportunity for a segfault to me. I suspect that line isn't what you really meant.

  3. #3
    Join Date
    Jun 2009
    Posts
    34

    Re: Music Organizing Program (NEED HELP)

    Quote Originally Posted by e_torstenson View Post
    Hi Aurora,

    Since this looks like a school assignment, I won't say exactly seems wrong to me, but I'll give you a hint...at least from a quick observations:

    [code]
    //this should put it in a vector
    bool Catalog::Read(ifstream &file)
    {
    string that_file;
    while(file >> that_file) //should read and store in the vector
    {
    getline(file, that_file);
    Song some_song(some_song.GetTitle(), some_song.GetArtist(), some_song.GetAlbum(), some_song.GetType() ); //take it apart and write the song on to that
    Add(some_song); //this should call Add and add the songs

    }
    return true;
    }
    [/code
    You are using the >> and getline functions in a suspicious way. You might take a look at the documentation for std::istream to see if these two functions really are appropriate for your needs.

    Next, instantiating some_song looks like a prime opportunity for a segfault to me. I suspect that line isn't what you really meant.
    ah i see but is the add song member function ok?

  4. #4
    Join Date
    Dec 2008
    Posts
    10

    Re: Music Organizing Program (NEED HELP)

    It looks like it should work.

    When you are having really bad results, it's always a good idea to look at it in pieces. So, if you aren't sure Catalog::Add(Song) isn't working, then you should write up a really simple test program to verify that it works. You could write a little program that adds 2 or three hard-coded songs to the catalog and then print the catalog. If that doesn't work, then you have only 2 places that you have to look (Add and print). Then, when that works, you can add something else to the test, etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured