Log Message Timestamp

#include <iostream>
#include <string>
using namespace std;

// Write your function here
void logMessage(string msg, bool t = false)
{
    if(t)
    {
    cout << "[123456] "<< msg << endl;
    }
    else
    {
        cout << msg;
    }
}
int main() {
    int mode;
    string msg;
    cin >> mode >> msg;

    if (mode == 0) {
        logMessage(msg);            // use default argument
    } else {
        logMessage(msg, true);      // enable timestamp
    }

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

0 Hello

Expected Output

Hello