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
Include Libraries: The necessary libraries are included at the beginning of the code.
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".
srand and rand Functions: The
srand
function is used to seed the random number generator with the current time, and therand
function is used to generate a random number.main Function: In the
main
function, a temporary email ID is generated using thegenerateTemporaryEmail
function and then printed to the console.Return Statement: The main function returns 0 to indicate successful execution.