CJCoding With Joseph
15free / daySign inCreate account

operator<< for a Color

A struct Rgb with three public ints r, g, b is given. Complete the free function ostream& operator<<(ostream& os, const Rgb& c) so that a color prints as rgb(, the three values separated by a comma and a space, then ). Do not print a newline; return os.

Output of Rgb red{255, 0, 0}; cout << red << "\n"; (see Expected Output).

Do NOT write a main function.

Expected Output:

rgb(255, 0, 0)
[rgb(10, 20, 30)]

= newline. The output ends with a newline — print one after the last line.

Hints2 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.