← Back to Streams
Question 636
operator<< for Playlist
operator<< for Playlist
A classPlaylistholding avector<string>of song names is given, together with a friend declaration foroperator<<. Define the free functionostream& operator<<(ostream& os, const Playlist& p)below the class so that a playlist prints as the wordPlaylist, the number of songs in parentheses, a colon, a space, and then the song names separated by a comma and a space. Print no newline; returnos. A playlist with songsa,b,cprints the output shown in Expected Output. An empty playlist prints onlyPlaylist(0):with nothing after the colon (no trailing space). Do NOT write a main function.
Expected Output:
Playlist(3): a, b, c Playlist(0): Playlist(1): solo
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsostream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.