Log Message Timestamp

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

void logMessage(const std::string& _msg, bool _timestamp = false)
{
    if ( _timestamp )
    {
        cout << "[123456] " << _msg << endl;
    }
    else
    {
        cout << _msg << endl;
    }
}

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