How to find '@" in a string

I have a mail.dat list which contains three different emails and some other comments. I know how to use"mail.dat"). What I want to do is use the find command to locate a string that contains'@' and output the three email addresses in to a file called addresses.dat. Does any one know how to code this?

mail.dat file
Date: Wed, 13 Aug 2003 17:12:33 EDT
Subject:Re: hi
John's email is

the program would output the following information on file addresses.dat

This is what I have so far.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()

ifstream inFile;
ofstream outFile;"mail.dat");"addresses.dat");


It depends on the format of your base file with the adresses (mail.dat)...

If you know the format, you could read in the lines and search for the @... Or read in every single string or word and also use std::find() or write an own-written function (but i think thats not what you want)

Or you could use regex'es (e.g. std::regex)...
closed account (DSLq5Di1)

Check the examples of find, find_first_of, last_of, etc.

The "From" and "To" fields shouldn't be a problem, email addresses in the body text may require additional logic to handle grammar and/or typos.
Topic archived. No new replies allowed.