Question: Write a C++ function which extracts an email address from a string. Your function will have the form string getEmail(string text) { ... } You
Write a C++ function which extracts an email address from a string. Your function will have the form
string getEmail(string text) { ... } You may only use C++ string features that we introduced in Week 2 lectures. You cannot use any other string functions.
You can assume that there is always a space before and after the email address. If there is more than one email address, just extract the first one. If there is no email address in the text, just return and empty string.
Your code should work correctly when called from the test code below:
// Test code your function should work with int main() { cout << getEmail("conor.mcardle@tcd.ie is my email address.") << "|" << endl; cout << getEmail("my email address is conor.mcardle@tcd.ie") << "|" << endl; cout << getEmail("Hi there! This is my email conor.mcardle@tcd.ie Get in touch any time!") << "|" << endl; } This should produce the output:
conor.mcardle@tcd.ie| conor.mcardle@tcd.ie| conor.mcardle@tcd.ie|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
