extracting email addresses from text files

Im trying to figure out how to filter out emails from
a form. Its working to a degree in that if the email address
is staggered from a name it works and pulls the address
perfectly. However, if the email address is on the same
line it will print out the entire line
such as "Pollbjhock, Juhjklia jpolcghock@ms.org"
I am trying to get this file to just extract
the emails and nothing more..any advice as to
whats missing?



#include <iomanip>
#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;





int main()

{

ifstream fin;
string fileName = "fileContaining.txt";
fin.open(fileName.c_str());


//create an empty list
const int MAX_EMAILS = 1000;
int nEmails = 0;
string Email[MAX_EMAILS];


while(!fin.eof())
{

string aEmail;
fin >> aEmail;
fin.ignore(1000,10);
getline(fin,aEmail);


if(aEmail.find("@")!=string::npos)
// true if an @ sign is found.
{
if(aEmail.find(",")!=string::npos)
// true if a comma has been found.
{




}

{
cout<< aEmail<<" saved\n";
ofstream address;
address.open("copyPaste.txt",ios::app );
address << aEmail << endl;
address.close();
aEmail.clear();
}

}


}
// close both files.















return 0;


}
Topic archived. No new replies allowed.