Temparory Email Id

Generating a Temporary Email ID in C++

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

std::string generateTemporaryEmail() {
    std::string email = "temp_email_";
    srand(time(0));
    int randomNumber = rand() % 1000;
    email += std::to_string(randomNumber) + "@example.com";
    return email;
}

int main() {
    std::string temporaryEmail = generateTemporaryEmail();
    std::cout << "Temporary Email ID: " << temporaryEmail << std::endl;
    return 0;
}

Code Explanation

  1. Include Libraries: The necessary libraries are included at the beginning of the code.

  2. generateTemporaryEmail Function: This function generates a temporary email ID. It concatenates the string "temp_email_" with a random number between 0 and 999, followed by "@example.com".

  3. srand and rand Functions: The srand function is used to seed the random number generator with the current time, and the rand function is used to generate a random number.

  4. main Function: In the main function, a temporary email ID is generated using the generateTemporaryEmail function and then printed to the console.

  5. Return Statement: The main function returns 0 to indicate successful execution.