|
-
July 28th, 2009, 04:53 PM
#1
Music Organizing Program (NEED HELP)
Last edited by aurorablaze07; July 30th, 2009 at 09:59 AM.
-
July 28th, 2009, 05:13 PM
#2
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.
-
July 28th, 2009, 05:16 PM
#3
Re: Music Organizing Program (NEED HELP)
 Originally Posted by e_torstenson
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?
-
July 28th, 2009, 05:34 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|