Using Strings to find email adresses.

I am given a generic file in which I must find all of the email addresses, take the, and place them into a new file. It's my first time really using strings so I'm not very solid on how to use them. I know the solution to the problem has something to do with the '@' character, but I'm not sure how to get the rest of the email address preceding this character. I haven't really done anything, so far I just have a sort of template going on. Any hints or tips? Or wanna just give me the answer? Anything helps!
// extract email addresses out of a document (mail.dat)
// and place them into a new file called addresses.dat.
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

int main()
{
ofstream addr;
mail.open("mail.dat");
addr.open("addr.dat");
string word;
ifstream addr;
while (!mail.dat.eof())
{
mail.dat >> word;
}
}
mail.close();

example for a ifstream
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
       int i = 0;//Initialize are very important
       string word[100];
       ifstream inFile;
       inFile.open("mail.dat");
       if( inFile.fail() )
             cout << "Unable to open file !" << endl; // Checking status of file

       if( inFile.is_open() ){
               while( !inFile.eof() ){//while it's not end of file
                        getline( inFile , word );//It's string . if u use cin , it will ignore those alphabet if a space is entered
                        i++;
               }
        }
        return 0;//Exit program
}


not really sure it's correct or not. but should be can work. just giving u the concept will do
Last edited on
Topic archived. No new replies allowed.