Log Message Timestamp

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

// Write your function here
void logMessage(string s, bool flag=false)
{
    if(flag == false){
        cout << s << endl;
    } else {
        cout << "[123456] " << s << 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