0

The function:

void cleanAlbum()

removes the token [None] from the album field of the songs that do not have a valid album.

I have a vector of Songs called collection and there are strings like

string artist;

string album;

string song_name;

I need to replace [None] with " " (6 whitespaces) in this collection for albums with name "[None]"

My code doesn't work:

     replace_if(collection.begin(), collection.end(), "[None]", "      ");
Josh Brown
  • 21
  • 4

1 Answers1

-1

It looks like you are trying to compare, your Song class to a string in your code. That won't work. If I were you I'd add a boolean variable to your Song class called isEmpty which will be true in the case where your were entering "[None]" and a function called empty() which returns true if the song is empty.

Using this your code should look like:

replace_if(collection.begin(), collection.end(), empty, "      ");

Here is a link to the documentation on the replace_if function, http://www.cplusplus.com/reference/algorithm/replace_if/ empty() might have to not be a member function of the Song class for this to work, in which case I'd advise giving it a different name.

jsmit42
  • 1
  • 1