Log Message Timestamp

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

// Write your function here
void logMessage(string msg,bool flag = false){
    if(!flag){
        cout<<msg;
    }
    else{
        // true → print a simulated timestamp followed by the message
        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