CJCoding With Joseph
15free / daySign inCreate account

operator<< for Playlist

A class Playlist holding a vector<string> of song names is given, together with a friend declaration for operator<<. Define the free function ostream& operator<<(ostream& os, const Playlist& p) below the class so that a playlist prints as the word Playlist, 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; return os.

A playlist with songs a, b, c prints the output shown in Expected Output.

An empty playlist prints only Playlist(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
Topics:
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.