In C++, we often want to print objects directly to the console or a log stream using std::cout << obj, rather than calling a specific method like obj.print(). To achieve this, we must overload the << operator. Since the << operator is a global function (the left side is std::ostream, not our class), it cannot be a member function. Therefore, it must be declared as a Friend to access the private data it needs to print.
Your task is to implement a class SystemStatus.
int code, std::string message.operator<< to print the object in the format: [Status: <code>] <message>.Program Flow:
N.N times.code and string msg.SystemStatus object.std::cout << obj << std::endl;.Input Format:
N.N lines: Integer code, followed by string msg.Output Format:
[Status: <code>] <message>Example:
Example 1
Input:
2
404 NotFound
200 OKOutput:
[Status: 404] NotFound
[Status: 200] OKConstraints:
friend std::ostream& operator<< ....os) to allow chaining.code and message must be private.
Input
2 404 NotFound 200 OK
Expected Output
[Status: 404] NotFound [Status: 200] OK