Log Message Timestamp

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

// Write your function here

void logMessage(string msg, bool timestamp = false){
    if(!timestamp) cout << msg;
    else cout << "[123456] " << 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